Stacks And Queues
Stack Operations
Visualize LIFO behavior with push, pop, and peek operations before moving into parentheses parsing and monotonic stack patterns.
O(1)
LIFO: last in, first outoperation: peekactive value: 48
Top
value48
value36
value24
value12
Base
Time
O(1)
Space
O(n)
Step Note
Peek reads the top stack item without removing it.
function peek(stack: number[]) {
if (stack.length === 0) return null
return stack[stack.length - 1]
}