Cheapest Mix of Ride Passes to Cover Planned Commute Days
Last updated: November 29, 2026
Quick Overview
A rider plans to commute on given days of the year; a 1-day pass, 7-day pass and 30-day pass cost c1, c7 and c30. Return the minimum total cost to cover every planned day.
Uber
November 29, 20260
0
0 solved
A rider plans to commute on given days of the year; a 1-day pass, 7-day pass and 30-day pass cost c1, c7 and c30. Return the minimum total cost to cover every planned day.
Uber has experimented with ride passes and memberships such as Uber One, and pricing analysts ask what the cheapest plan would be for a given usage pattern. The screen checks a clean 1D DP over days and the choice between iterating over calendar days or only over travel days.
What the Interviewer Expects
- Define the DP state over days or over travel-day indices
- Write the recurrence for the three pass types
- Skip non-travel days cheaply
- Use binary search or pointers when iterating over travel days only
- Explain why greedy (always buy the cheapest per-day pass) fails
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
- What if passes can start on any day, not only a travel day? Does that change the answer?
- How would you generalize to arbitrary pass durations and prices?
- What if travel days span several years?
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: sorted distinct
days(1..365),costs = [c1, c7, c30]. - A pass bought on day d covers d through d + duration - 1.
- Output: minimum total cost....
High-Level Design
Let dp[i] be the minimum cost to cover travel days i..end. On travel day days[i], buying a pass of duration D covers every travel day before days[i] + D; the next uncovered index is found with...