Problem 241285 · easy · Phase 02 Linear Data Structures

Finishing Position

arrays · counting · ranking

times holds the finishing times (in seconds) of every runner in a race, and i is the index of one runner. Return that runner's finishing position: 1 plus the number of runners with a strictly smaller time. Runners with equal times share the same position.

Examples

Input:  times = [125, 112, 130, 112], i = 0
Output: 3
Explanation: Two runners (both at 112) were faster.

Input:  times = [125, 112, 130, 112], i = 1
Output: 1

Constraints

  • 1 <= len(times) <= 10**5
  • 0 <= i < len(times)
  • Target: O(n) time.

Goals

  • Rank one element by counting how many are strictly better
  • Handle ties so equal times share a position
Starting Python…