Dynamic Programming, Scheduling, And Set Cover
Asked of: Software Engineer
Last updated

What's being tested
These problems test dynamic programming for combinatorial optimization, especially when brute force over subsets or schedules is too large. Expect to recognize weighted interval scheduling, knapsack/subset-cover search, and memoized multidimensional state while explaining correctness, tie-breaking, and complexity.
Patterns & templates
-
Weighted interval scheduling — sort jobs by end time; use
bisect_rightto find previous compatible job; recurrencedp[i] = max(dp[i-1], profit[i] + dp[p(i)]). -
Inclusive/exclusive interval handling — clarify whether a job ending at
tcan precede one starting att; this changesbisect_rightvsbisect_left. -
Set cover via bitmask DP — map required services to bits; update
dp[mask | providerMask] = minCost; works well when services 20–25. -
Backtracking with pruning — enumerate combinations for small
n; sort by cost, prune when current cost exceeds best, and use deterministic tie-breaking. -
Knapsack-style capacity DP — for capacity-constrained property selection, track reachable sums/counts; reconstruct minimal set and handle exact vs at-least constraints.
-
Memoization on multidimensional state — use
@lru_cacheover(idx, remainingA, remainingB, remainingC)or normalized tuples; prune dominated states aggressively. -
Cost/profit overflow awareness — use 64-bit integers conceptually; Python is safe, but mention
long long/int64in typed languages.
Common pitfalls
Pitfall: Treating interval scheduling as greedy by highest reward or shortest duration; weighted scheduling needs DP because local choices can block better combinations.
Pitfall: Forgetting deterministic tie-breaking when multiple minimal covers or property sets exist; define order before coding.
Pitfall: Using exponential subset enumeration when the intended constraint supports bitmask DP, binary search, or memoization.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Find minimal property set in neighborhoodAirbnb · Software Engineer · Technical Screen · Medium
- Design menu DP and optimize for three itemsAirbnb · Software Engineer · Technical Screen · Medium
- Maximize reward by scheduling jobsAirbnb · Software Engineer · Technical Screen · Medium
- Solve and optimize menu combo DPAirbnb · Software Engineer · Technical Screen · Medium
- Compute minimum-cost service coverAirbnb · Software Engineer · Technical Screen · Medium
- Maximize profit from non-overlapping jobsAirbnb · Software Engineer · Onsite · Medium
Related concepts
- Dynamic Programming, Backtracking, And Combinatorial SearchCoding & Algorithms
- Dynamic Programming, Backtracking, and State-Space SearchCoding & Algorithms
- Dynamic Programming And Mutable Range QueriesCoding & Algorithms
- Dynamic Programming And Combinatorial CountingCoding & Algorithms
- Dynamic Programming And MemoizationCoding & Algorithms
- Greedy, Heaps, And Scheduling OptimizationCoding & Algorithms