Cheapest Mix of Day, Week, and Month Delivery Passes
Last updated: November 29, 2026
Quick Overview
A small business needs courier service on specific days of the year and can buy 1-day, 7-day, or 30-day passes at given prices. Return the minimum total cost to cover every required day.
Amazon
November 29, 20260
0
0 solved
A small business needs courier service on specific days of the year and can buy 1-day, 7-day, or 30-day passes at given prices. Return the minimum total cost to cover every required day.
A 1D DP over calendar days in the Amazon online assessment style, similar to how Amazon Business customers pick between pay-per-use and subscription plans. The interviewer checks a correct recurrence that looks back by pass duration and handles days that need no coverage.
What the Interviewer Expects
- Define cost[d] as the cheapest way to cover required days up to d
- Carry cost forward on days that need no coverage
- Look back 1, 7, and 30 days and clamp at 0
- O(D) time where D is the last day
- Discuss the alternative indexed by required days only
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 the calendar spans 10^9 days but only 10^5 required days?
- How would you return which passes to buy?
- What if a pass bought on day d covers d through d+6 only on weekdays?
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 list days in 1..365 and prices = [day, week, month]. A pass bought on day d covers d through d + duration - 1. Output: minimum total cost....
High-Level Design
Think backwards from day d: if d needs coverage, the pass covering it was bought at most duration - 1 days earlier, and everything before that window must be covered on its own. So `cost[d] = min(co...