Cheapest Set of Fixed-Length Access Passes Covering Usage Days

Last updated: November 29, 2026

Quick Overview

A customer needs API access on a sorted list of days. Given plans of the form `(duration_days, cost_cents)`, each covering `duration_days` consecutive days from purchase, return the minimum total cost to cover every usage day and one purchase schedule that achieves it.

Stripe
Coding & Algorithms
Software Engineer
Stripe
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A customer needs API access on a sorted list of days. Given plans of the form `(duration_days, cost_cents)`, each covering `duration_days` consecutive days from purchase, return the minimum total cost to cover every usage day and one purchase schedule that achieves it.

Stripe Billing supports prepaid and fixed-term plans, and recommending the cheapest plan mix for observed usage is a realistic product helper. The interviewer checks that you see optimal substructure over usage days rather than calendar days, use binary search to jump ahead, and reconstruct the actual purchases rather than only the number.

What the Interviewer Expects
  • Define the DP state over usage-day indices, not over all calendar days
  • Use `bisect` to find the first usage day a plan does not cover
  • Fill the DP from the right so each state depends on later states
  • Store choices to reconstruct the purchase schedule
  • Handle an arbitrary number of plans, not just three hard-coded ones
Key Topics to Cover
dynamic programming
binary search
reconstruction
pricing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if a plan can be started on any day, not only on a usage day?
  • How would you handle a plan with a per-day usage cap?
  • How does the solution change if days span multiple years and plans are monthly calendar periods?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: strictly increasing integer days and a non-empty list of (duration, cost) plans. A plan bought on day d covers days d through d + duration - 1. It is only ever optimal to buy on a usa...

High-Level Design

Let dp[i] be the cheapest way to cover days[i:], with dp[n] = 0. Buying plan p on days[i] covers up to days[i] + duration - 1, and j = bisect_left(days, days[i] + duration) is the next u...


Submit Your Answer
Markdown supported