Ctrl K

Longest Drop From End to End

Medium
You get an integer array values. Call a contiguous non-empty span of the array *dropping* if its first element is strictly greater than its last one. What happens in between does not matter. Return the length of the longest dropping span, or 0 if there is none. A single-element span is never dropping, since its first and last elements are the same.
Example 1
values=[4, 9, 2, 8, 3, 10] → 5

The span [4, 9, 2, 8, 3] starts at 4 and ends at 3, and 4 > 3. Its length is 5, and nothing longer works: the last element 10 is bigger than every possible start.

Example 2
values=[2, 2, 5, 7] → 0

No span starts with a value strictly greater than its end, so the answer is 0.

Example 3
values=[6, 1, 1, 1, 5] → 5
Constraints
  • 1 ≤ len(values) ≤ 10⁵
  • -10⁹ ≤ values[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFix the Middle of the Line MediumMost Pieces Sorted Separately MediumConvoys at the Finish MediumOutclassed Heroes MediumPeaks in Plain Sight Medium
loading Python…
Input
values=[4, 9, 2, 8, 3, 10]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 129 tests on the server, hidden ones included.