Ctrl K

Pairs With a Steep Drop

Hard
You are given an integer array values. A pair of indices (i, j) is a **steep drop** if i < j and values[i] > 2 · values[j], meaning the earlier number is strictly greater than twice the later one. Return the number of steep drops in the array.
Example 1
values=[9, 4, 2, 5] → 2

The pairs (0, 1): 9 > 2 · 4 and (0, 2): 9 > 2 · 2 count. The pair (1, 2) does not: 4 is not greater than 2 · 2, and a tie is not enough. Total: 2.

Example 2
values=[1, 2, 3, 4] → 0

The array is increasing, so no value exceeds double a later one.

Example 3
values=[3, -1, 0] → 2

3 > −2 and 3 > 0 hold, while −1 > 0 does not, giving 2 pairs.

Constraints
  • 1 ≤ len(values) ≤ 5 · 10⁴
  • -2³¹ ≤ values[i] ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSmaller Values to the Right HardWindow Sums Within a Band HardCost of Filling a Sorted Shelf HardTriples Both Rankings Agree On HardPairs Within a Shifted Gap Hard
loading Python…
Input
values=[9, 4, 2, 5]
Expected
2

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