~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Binary search on the answer
Monotonic feasibility check + search the smallest value that works.
Notes
Recognise it when: the question is "minimum capacity / speed / time such that X is possible", feasibility is monotone in the answer, and checking one candidate is easy (a greedy O(n) check).
def feasible(cap):
days, load = 1, 0
for w in weights:
if load + w > cap: days, load = days + 1, 0
load += w
return days <= D
lo, hi = max(weights), sum(weights)
while lo < hi:
mid = (lo + hi) // 2
if feasible(mid): hi = mid
else: lo = mid + 1
return lo
Gotchas: pick bounds that are definitely infeasible or feasible (lo = the tightest lower bound). Use integer ceiling division, -(-a // b). For "maximum such that", flip the logic.
11 problems
Interview roadmap
Binary search Sorted lookups, rotations, searching the answer.
Binary search on the answer guide
- Basics: smallest value that passes a check basics easy
- Biggest square cookies py · c++ · java easy
- Koko Eating Bananas py · c++ · java medium
- Capacity to Ship Packages Within D Days py · c++ · java medium
- Split Array Largest Sum py · c++ · java medium
- Earliest time to build t products py · c++ · java medium
- OA: Distributed mode and median under a bandwidth budget 3 levels Anthropic hard
- Find Median In Large Array AirbnbGoogle medium
- Maximize portfolio floor value Uber py · c++ · java medium
- Maximum Throughput SnowflakeTwo Sigma py · c++ · java medium
- Sqrt(x) py · c++ · java easy