A Stack is a linear data structure that follows a particular order in which the operations are performed. The order is LIFO(Last In First Out) which implies that the element that is inserted last, comes out first.
It behaves like a stack of plates, where the last plate added is the first one to be removed. Pushing an element onto the stack is like adding a new plate on top. Popping an element removes the top plate from the stack.
Basics
Implementations in Different Languages
Easy Problems
- The Celebrity Problem
- Queue using Stacks
- Two stacks in an array
- Infix to Postfix
- Prefix to Infix
- Prefix to Postfix
- Postfix to Prefix
- Postfix to Infix
- Infix To Prefix
- Check for balanced parentheses
- Evaluation of Postfix Expression
- Reverse a stack using recursion
- Reversing the first K of a Queue
- A DS with O(1) Operations
Medium Problems
- k Stacks in an Array
- Mergable Stack
- Stack using Queues
- Previous Smaller Element
- Next Greater Element
- Stock Span Problem
- Buildings Facing Sun
- Next Smaller of next Greater
- Next Greater Frequency
- Max product of indexes of greater on left and right
- Iterative Tower of Hanoi
- Sort a Stack
- Reverse a Stack
- Delete middle of a stack
- Check for queue sortable
- Check for stack sortable
- Index of closing bracket for a given opening bracket
- Max Diff between nearest left and right smaller
- Delete consecutive same words
Hard Problems
- Largest Rectangle in a Histogram
- Sum of Max of all Subarrays
- Max of Mins of every window size
- Stack that supports getMin()
- Stack with max frequency
- Longest valid substring
- Check Redundant Bracket
- Stack Permutations
- Remove brackets containing + and – operators
Quick Links :