Solve and optimize menu combo DP
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates dynamic programming and combinatorial optimization skills, focusing on state definition, transitions, memoization, pruning dominated offers, and minimizing state space for menu-combo minimum-cost problems in the domain of Coding & Algorithms.
Constraints
- 1 <= N <= 6
- 0 <= S <= 100
- 0 <= needs[i] <= 10
- 1 <= prices[i] <= 10^4
- Each offer is length N+1: first N non-negative integers are quantities, last is offer price (0 <= offer price <= 10^5)
- No extra items allowed: an offer can be applied only if all its quantities are <= the remaining needs
- All inputs are integers
Hints
- Model the state as the remaining needs vector; use memoization with the state as a tuple.
- Baseline for any state: buy remaining items individually; try applying each valid offer to reduce the state.
- Prune offers whose price is >= the cost of buying their quantities individually, and offers that have any quantity exceeding needs.
- For N=3, build a bottom-up 3D DP of size (needs[0]+1)*(needs[1]+1)*(needs[2]+1), initializing with individual-buy costs and relaxing with offers.
- Skip offers that exceed current remaining needs to enforce the no-extras rule.