Ctrl K

Pairs Off the Pace

Medium
A runner writes down a track marker every minute: marks[i] is the marker at minute i (0-based). A pair of minutes (i, j) with i < j keeps pace when the marker grew by exactly as much as the number of minutes that passed: marks[j] - marks[i] = j - i. Otherwise the pair is off pace. Return the number of pairs that are off pace.
Example 1
marks=[3, 4, 9, 6] → 3

Pairs (0, 1), (0, 3) and (1, 3) keep pace: 4 − 3 = 1 − 0, 6 − 3 = 3 − 0, 6 − 4 = 3 − 1. The three pairs involving index 2 are off pace. The answer is 3.

Example 2
marks=[5, 5, 5] → 3

The values stay flat while the indices grow, so all 3 pairs are off pace.

Example 3
marks=[8] → 0

There are no pairs.

Constraints
  • 1 ≤ len(marks) ≤ 10⁵
  • 1 ≤ marks[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPairs Balanced by Their Mirrors MediumPhoto Frames of the Same Shape MediumNumbers and Their Mirrors MediumPrimes Along Grid Rays MediumCorners Made of Ones Medium
loading Python…
Input
marks=[3, 4, 9, 6]
Expected
3

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