Cheapest Prepaid Recharge Combination to Cover N Days
Last updated: November 29, 2026
Quick Overview
Given a telecom operator's prepaid plans as (price, validity in days), which can be bought repeatedly and stacked back to back, find the minimum cost to keep a number active for at least N days.
PhonePe
November 29, 20260
0
0 solved
Given a telecom operator's prepaid plans as (price, validity in days), which can be bought repeatedly and stacked back to back, find the minimum cost to keep a number active for at least N days.
Mobile recharge is one of PhonePe's highest-frequency use cases, and a plan advisor that suggests the cheapest way to cover a period is a natural product feature. The interviewer checks that you spot the unbounded knapsack structure, handle the 'at least N days' overshoot, and avoid greedy by price per day.
What the Interviewer Expects
- Recognize an unbounded knapsack or coin-change shape
- Handle coverage of at least N days, allowing overshoot
- Show a counterexample to greedy by cost per day
- Implement bottom-up DP with clear state definition
- Discuss reconstruction of the actual plan list
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 list of plans to buy, not just the cost.
- Some plans have a data cap and the user needs at least D GB over the period. How does the state change?
- N is up to 3650 and there are 200 plans. Is the DP still fast enough on the request path?
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: plans as (price, validity_days) and days_needed. Plans can repeat. Output: minimum total price to cover at least days_needed days, -1 if impossible (no plans), 0 when no days are ne...
High-Level Design
Define dp[d] as the minimum cost to cover at least d days. The last plan bought covers validity days, so the rest must cover at least max(0, d - validity). Then `dp[d] = min over plans of dp[m...