knaxuslearn · build · ship

week 5 of 15

Stacks and queues

Get comfortable with these coding mechanics first: stack push, pop and peek. Queue or deque operations. Storing indexes or tuples on a stack. Template to type from memory by the end of the week: monotonic stack: for each element, while the stack top is worse, pop and settle it. Then push.

  1. 40Valid Parentheses (opens LeetCode in a new tab)Stack matchingEasy
    Common mistake
    Popping from an empty stack.
  2. 41Min Stack (opens LeetCode in a new tab)Stack with an auxiliary minimumMedium
    Common mistake
    Forgetting that the min must be removed together with the value.
  3. 42Evaluate Reverse Polish Notation (opens LeetCode in a new tab)Expression stackMedium
    Common mistake
    Operand order for - and /. Division truncates toward zero.
  4. 43Daily Temperatures (opens LeetCode in a new tab)Monotonic stackMedium
    Common mistake
    Storing values instead of indexes.
  5. 44Car Fleet (opens LeetCode in a new tab)Sort + monotonic stackMedium
    Common mistake
    Sorting positions without keeping each speed paired with its position.
  6. 45Asteroid Collision (opens LeetCode in a new tab)Stack simulationMedium
    Common mistake
    Handling all three outcomes (top wins, new wins, both die).
  7. 46Largest Rectangle in Histogram (opens LeetCode in a new tab)Monotonic stack (hard)Hardcore
    Common mistake
    Getting the width calculation wrong, and forgetting the final flush.
  8. 47Sliding Window Maximum (opens LeetCode in a new tab)Monotonic dequeHardcore
    Common mistake
    Storing values instead of indexes, so you cannot expire the front.