FunctionRacerProblemsRace

Longest Hill

MediumArraysPython, JavaScript, TypeScript, Java, C++

A hill is a stretch of consecutive items of heights that strictly rises for one or more steps and then strictly falls for one or more steps, with no flat step anywhere inside it. So a hill has at least 3 items and exactly one top, the items strictly increase up to the top and strictly decrease after it.

Return the number of items in the longest hill. If heights has no hill at all, return 0.

Example 1

heights [2,1,4,7,3,2,5]
returns 5

1, 4, 7, 3, 2 rises to 7 and then falls: five items. The final 5 starts a new rise but never falls.

Example 2

heights [2,2,2]
returns 0

Flat steps are not allowed, so three equal heights form no hill.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems