readings (positions are 0-based). You are given two thresholds, min_gap and min_jump. A pair of positions p ≤ q works if q - p ≥ min_gap and |readings[q] - readings[p]| ≥ min_jump. When min_gap = 0, the two positions may coincide.
Find a working pair with the smallest possible q. Choose the partner p for that q among positions 0 to q - min_gap as follows:
- if the lowest reading among them works, take it (the earliest position if there is a tie);
- otherwise take the highest one (again the earliest among equals).
Return [p, q], or [-1, -1] if no pair works. Aim for something faster than O(n²).readings=[4, 9, 2, 6, 10], min_gap=2, min_jump=5 → [2, 4]
For q = 2 and q = 3 no allowed earlier reading differs from the current one by 5 or more. For q = 4 the allowed p are 0 to 2; the lowest reading is 2 (p = 2), and 10 - 2 = 8 ≥ 5.
readings=[8, 8, 1], min_gap=1, min_jump=6 → [0, 2]
For q = 2 the lowest of 8, 8 is not below 1, but the highest (8, first at p = 0) is 7 higher.
readings=[3, 5], min_gap=0, min_jump=0 → [0, 0]
With both thresholds at zero, the pair [0, 0] already works.
readings=[4, 9, 2, 6, 10], min_gap=2, min_jump=5
[2, 4]
Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.