Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Concept

Overview

LIFO · push, pop, and why "the top" matters
step 1 / 12
3
7
2
9
[0][1][2][3]
top ↓
(empty)
stack
Concept
1stack = [] // LIFO container
2push(x): place x on TOP
3pop(): remove and return the TOP
4peek(): read the TOP without removing
5// every operation is O(1)
state
  • orderLIFO

line 1A stack is the simplest container with a personality: you may only touch the TOP. Add with push, remove with pop — the LAST thing in is the FIRST thing out (LIFO).