AlgoViz
HomeStack

Stack

Last-in first-out — perfect for matching and 'nearest' problems.

0/ 38 understood · 0%
Walkthroughs
17
Problems
38
Start here
38 shown
  1. Valid ParenthesesOpeners wait on a stack for their matchEasy
  2. Min StackO(1) minimum alongside push/popMedium
  3. Evaluate Reverse Polish NotationOperators pop their two operandsMedium
  4. Daily TemperaturesMonotonic stack of 'waiting' daysMedium
  5. Practice problems
  6. Implement Stack using ArraysAn array plus a top indexEasy
  7. Implement Queue using ArraysA circular buffer with two indicesEasy
  8. Implement Stack using QueueRotate after each pushEasy
  9. Implement Queue using StackTwo stacks, in and outEasy
  10. Implement stack using LinkedlistPush and pop at the headEasy
  11. Implement queue using LinkedlistHead to dequeue, tail to enqueueEasy
  12. Balanced ParanthesisPush openers, match on closeEasy
  13. Implement Min StackStore the minimum alongside each elementHard
  14. Infix to Postfix ConversionOperands out, operators on the stackMedium
  15. Prefix to Infix ConversionScan right to left, combine two operandsMedium
  16. Prefix to Postfix ConversionRight to left, operator lastMedium
  17. Postfix to Prefix ConversionLeft to right, operator firstMedium
  18. Postfix to Infix ConversionLeft to right, bracket each joinEasy
  19. Infix to Prefix ConversionReverse, convert, reverse againMedium
  20. Next Greater ElementDecreasing stack, popped means answeredMedium
  21. Next Greater Element - 2Walk the array twice for the wrap-aroundMedium
  22. Next Smaller ElementIncreasing stack insteadMedium
  23. Number of Greater Elements to the RightCount, so a stack is not enoughEasy
  24. Trapping RainwaterWater above a bar is bounded by the taller wallsHard
  25. Sum of Subarray MinimumsCount the subarrays each element dominatesMedium
  26. Asteroid CollisionThe stack holds the survivors so farMedium
  27. Sum of Subarray RangesSum of maxima minus sum of minimaMedium
  28. Remove K DigitsGreedily drop a digit bigger than its successorMedium
  29. Largest rectangle in a histogramEach bar's rectangle spans to the smaller neighboursHard
  30. Maximum RectanglesA histogram per rowHard
  31. Sliding Window MaximumA deque of useful indicesHard
  32. Stock span problemJump back to the previous greater priceHard
  33. Celebrity ProblemEach question eliminates one personHard
  34. LRU CacheHash map plus a doubly linked listMedium
  35. LFU CacheOne list per frequency, plus a minimumHard
  36. Decode StringStack the count and the prefix at each bracketMedium
  37. Longest Valid ParenthesesStack the indices, measure from the last unmatchedMedium
  38. Monotonic StackKeep the stack sorted; each element enters and leaves onceMedium
  39. Largest Rectangle in HistogramMonotonic stack over the bar heightsMedium