Skip to the code
cf.
+25 XP

#599 Longest Rise and Fall in a Chart

medium

A traffic chart highlights its longest "spike": a run of neighboring points that strictly rises to a peak and then strictly falls. A spike has at least 3 points, with at least one point before the peak and at least one after it.

Write longestSpike(points) that returns the number of points in the longest spike, or 0 if there is none.

Example 1

Input: points = [2,1,4,7,3,2,5]
Output: 5

1, 4, 7, 3, 2 rises to 7 and falls.

Example 2

Input: points = [2,2,2]
Output: 0

Flat points never rise or fall.

Constraints

  • 0 <= points.length <= 100000
  • 0 <= points[i] <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).