โ Coding Interview Prep (LeetCode) learning pathCoding Interview Prep (LeetCode) ยท Module 6 of 10
Stacks, queues and binary search
Stacks handle nesting; binary search halves the search space.
๐ Key ideas
- Valid parentheses: push opening brackets, pop on closing ones.
- Monotonic stacks find the next greater element in O(n).
- Queues power breadth-first search.
- Binary search on a sorted array is O(log n).
- Binary search on the answer: guess a value, test it, and halve the range.
๐ก Real-life example: A stack is a pile of exam papers; binary search is guessing a number when told "higher" or "lower".
Monotonic stackStack kept increasing or decreasing
Binary searchHalving search on sorted data
Search on answerBinary search over possible results
midMiddle index in binary search