Katkat

Compute the Eddington number from ride distances

LiftoffSoftware Engineer · Onsite

Last updated

This question evaluates a candidate's competence in array manipulation, ordering/selection techniques, counting thresholds, and algorithmic complexity analysis required to compute the Eddington number.

Given a list of positive integers distances, where distances[i] is the distance traveled on day i, compute the cyclist’s Eddington number E:

E is the largest integer such that there are at least E days with distance ≥ E.

Return E.

Examples:

  • distances = [1, 3, 3, 5, 6] → E = 3 (three days have distance ≥ 3)
  • distances = [10, 8, 5, 4, 3] → E = 4 (four days have distance ≥ 4)
  • distances = [1, 1, 1] → E = 1

Constraints: 1 ≤ n ≤ 2e5, 1 ≤ distances[i] ≤ 1e9. Aim for an efficient solution.