Agents · 11
Packing the most relevant chunks into a fixed token window is knapsack — greedy by relevance loses.
Reaching a goal with the fewest tool-calls is rarely the cheapest plan — orchestration is min-cost planning.
You can't max top-k and rerank for free — a latency budget forces the tradeoff, and chunk size has a sweet spot.
Route each call to the cheapest tool that's capable enough — defaulting to the most powerful model burns budget.
Hand off to a specialist only when the gain beats the handoff cost — constant switching costs as much as never switching.
Put the stable, reusable context first — one early-changing segment busts the cached prefix for everything after it.
Under a context cap, summarising a bulky-but-useful turn can beat keeping it whole or dropping it.
Stack only the guardrails you need to hit the safety target — running every check is wasted latency.
Pick tests for marginal coverage — a second test hitting the same bug-classes adds nothing.
A cheap, flaky first attempt with a reliable fallback can beat one expensive reliable call — in expectation.
Assign N agents to N distinct tasks for minimum total cost — a min-cost matching, not a row-by-row greedy. Each agent's own cheapest task collides on shared favourites and overpays.
System Design · 14
Minimising the busiest server's load is multiprocessor scheduling — place the heaviest requests first, not round-robin.
Batching trades latency for throughput-per-server — meet the SLA with the fewest consumers, not the smallest batch.
Placing a node on the ring relieves the hotspot — and only the slice of keys in its arc re-homes, not the whole keyspace.
Range-shard by load, not by key count — equal-sized ranges hotspot when the data is skewed.
Rightsize to the demand curve — provisioning for peak wastes money, but scaling every interval pays churn.
Bursts need bucket capacity, not just refill rate — pouring the whole budget into rate still drops spikes.
Past the concurrency knee, adding workers reduces throughput — contention collapses the system.
Pool size is a U-curve — too small queues requests, too large wastes idle connections.
Build only the indexes that pay for their storage on the query mix — indexing everything is a tax on every write.
Cache placement is facility location — cover the users by weighted distance, don't pile caches on the busiest city.
Cover every region with the fewest edge PoPs — minimum set cover. Greedy 'most-coverage-first' is a strong heuristic but not always optimal.
Packing services onto the fewest capacity-bounded VMs is bin packing — first-fit-decreasing can waste a VM; the true minimum needs a search.
On one server, run the shortest job first — a job's wait is the sum of every service time ahead of it, so a long job up front taxes the whole queue.
Connect every node at the lowest total link cost — that's a minimum spanning tree. Kruskal: add the cheapest edge that joins two separate components, skipping any that would form a cycle.
Algorithms · 16
LRU is a guess; Belady (evict the item used farthest in the future) is the provable optimum.
The shortest path minimises edge cost, not hop count — fewest stops is a trap.
Greedy 'largest coin first' isn't optimal for arbitrary denominations — minimum-coin change is a DP.
Earliest-finish greedy maximises the number of jobs, not their value — weighted scheduling is a DP.
Fixed-length codes waste bits — frequent symbols deserve short codes; Huffman's greedy is the optimal prefix code.
Maximize a sum with no two adjacent picks — the House Robber DP. 'Grab the biggest' and 'take every other' both lose.
Schedule unit jobs before their deadlines to maximize profit — highest-profit-first, latest free slot. Earliest-deadline-first chases count, not profit.
Buy once, sell later, maximize profit — track the min-so-far. 'Buy the lowest, sell the highest' fails when the high comes before the low.
Fit the most non-overlapping meetings into one room — sort by end time, take the next that starts on/after the last end. Picking by earliest start blocks more than it fits.
Slice a cable into priced piece-lengths summing to exactly its length for the most money — that's an unbounded-knapsack DP, not best-price-per-unit greed.
Pick the contiguous run of days with the largest total — Kadane's pass extends while it helps and resets when the running sum turns into a drag. Summing only the positive days fails.
Cross the distance in the fewest fill-ups: don't stop at the first low-tank station — bank the biggest refills you've already passed. That's the heap greedy.
Find the longest run of strictly increasing values that keeps the original order. Greedily taking every bigger number can trap you in a short chain — the LIS sometimes skips an early value to climb higher later.
Two walls hold water = width × the shorter wall. Sweep from the widest pair and always move the shorter wall inward — grabbing the two tallest bars ignores width.
Run jobs in Earliest-Due-Date order to minimize the worst lateness on one server — shortest-job-first feels busy but lets a tight deadline blow up.
Cover every alert window with the fewest watch times — sort windows by end, plant a point at the end of the first uncovered window. Stabbing by earliest start uses more points.