Continue here
Which tool when — comparison
This hub splits one overloaded interview bucket into two focused guides. Use the table to pick a door, then go deep.
| Signal in the prompt | Reach for | Guide |
|---|---|---|
| Sorted array / monotone yes-no on a number | Binary search / search-on-answer | Binary search |
| Nesting, undo, next greater/smaller | Stack / monotonic stack | Stacks & heaps |
| Top-K, streaming extreme, merge K lists | Heap | Stacks & heaps |
| Need full order once | Sort (not heap) | — |
How to study this pair
- Read binary search first — nail the invariant sentence.
- Do 2 classic BS + 2 search-on-answer problems.
- Then stacks & heaps — monotonic stack before heap.
- Do 2 next-greater + 2 top-K problems.
- Mix a mock that could be either (e.g. kth element — heap vs quickselect vs sort).
Interview takeaway
Open the focused post — this hub is only the map. Invariants live in the deep dives.
Shared practice set
- Search Insert Position / First Last Position
- Koko Eating Bananas
- Daily Temperatures
- Kth Largest Element
- Top K Frequent Elements
- Find Median from Data Stream
Pattern bank (hub links)
Eight high-yield questions across this hub — open the deep dive for full solutions.
- Rotated search — mid vs ends invariant
- Koko / shipping — binary search on answer
- Split array largest sum — same monotonic ok()
- Daily temperatures — monotonic stack
- Largest rectangle — stack of indices
- Top K frequent — heap or bucket sort
- Merge K lists — min-heap of heads
- First/last position — lower/upper bound