โ† Coding Interview Prep (LeetCode) learning path
Coding Interview Prep (LeetCode) ยท Module 6 of 10

Stacks, queues and binary search

Stacks handle nesting; binary search halves the search space.

๐Ÿ“– Key ideas

  1. Valid parentheses: push opening brackets, pop on closing ones.
  2. Monotonic stacks find the next greater element in O(n).
  3. Queues power breadth-first search.
  4. Binary search on a sorted array is O(log n).
  5. 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