Compute the Eddington number from ride distances
Problem: Compute the Eddington Number
Given a list of positive integers distances, where distances[i] represents the distance traveled on day i, your task is to compute the cyclist’s Eddington number E.
Definition of Eddington Number E
E is defined as the largest integer such that there are at least E days with a distance traveled greater than or equal to E.
Examples
distances = [1, 3, 3, 5, 6]→E = 3(Explanation: Three days have a distance ≥ 3:3,3,5,6. IfE=4, only5,6are ≥ 4, which is 2 days, not 4. SoE=3is the largest.)distances = [10, 8, 5, 4, 3]→E = 4(Explanation: Four days have a distance ≥ 4:10,8,5,4. IfE=5, only10,8,5are ≥ 5, which is 3 days, not 5. SoE=4is the largest.)distances = [1, 1, 1]→E = 1
Constraints
1 <= n <= 2e5(wherenis the number of days/length ofdistancesarray)1 <= distances[i] <= 1e9
Requirement
Aim for an efficient solution.
AI interview prep
Core dilemma
Optimizing the search for the Eddington number 'E' within given constraints (N up to 2e5, distance values up to 1e9), which necessitates an efficient algorithm beyond brute-force iteration over all possible 'E' values.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Compute the Eddington number from ride distances
Problem: Compute the Eddington Number
Given a list of positive integers distances, where distances[i] represents the distance traveled on day i, your task is to compute the cyclist’s Eddington number E.
Definition of Eddington Number E
E is defined as the largest integer such that there are at least E days with a distance traveled greater than or equal to E.
Examples
distances = [1, 3, 3, 5, 6]→E = 3(Explanation: Three days have a distance ≥ 3:3,3,5,6. IfE=4, only5,6are ≥ 4, which is 2 days, not 4. SoE=3is the largest.)distances = [10, 8, 5, 4, 3]→E = 4(Explanation: Four days have a distance ≥ 4:10,8,5,4. IfE=5, only10,8,5are ≥ 5, which is 3 days, not 5. SoE=4is the largest.)distances = [1, 1, 1]→E = 1
Constraints
1 <= n <= 2e5(wherenis the number of days/length ofdistancesarray)1 <= distances[i] <= 1e9
Requirement
Aim for an efficient solution.