Longest Run of Consecutive Calendar Days a Driver Was Active
Last updated: November 29, 2026
Quick Overview
Given an unsorted list of integer day numbers on which a driver completed at least one trip (duplicates possible), return the length of the longest run of consecutive days, in O(n) time.
Uber
November 29, 20260
0
0 solved
Given an unsorted list of integer day numbers on which a driver completed at least one trip (duplicates possible), return the length of the longest run of consecutive days, in O(n) time.
Driver incentive programs at Uber reward streaks, so a streak calculation over messy activity logs is a natural screen question. The interviewer wants the O(n) set-based approach and expects you to explain why each day is visited a constant number of times.
What the Interviewer Expects
- Mention the O(n log n) sort solution as a baseline
- Use a hash set and only start counting at run beginnings
- Argue the amortized O(n) bound clearly
- Handle duplicates and empty input
- Connect to how a streak might reset across time zones
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the start and end day of the longest streak as well
- What if days arrive as a stream and you must report the current longest streak after each insert?
- How would you allow one grace day inside a streak?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of integers
days(for example days since epoch), unsorted, may repeat. - Output: length of the longest set of values
d, d+1, ..., d+L-1all present. - Constraint: O(n) expected time....
High-Level Design
Sorting would work in O(n log n). To get linear time, put all days in a set. A day d is the start of a run only if d - 1 is not in the set. From each start, walk forward while d + 1 exists. ...