Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Max Stack
Bookmark
Two Stacks
Heap + Lazy
TreeMap + DLL
Input
Example 1
Example 2
Example 3
Custom
operations
=
[MaxStack, push, push, push, top, popMax, top, peekMax, pop, top]
,
values
=
[null, 5, 1, 5, null, null, null, null, null, null]
Operation
-
Result
-
Doubly Linked List (Stack)
TreeMap
(empty)
(empty)
Operation
-
Result
-
Doubly Linked List (Stack)
TreeMap
(empty)
(empty)
Operation
push(5)
Result
-
Doubly Linked List (Stack)
TreeMap
5
← top
← bottom
(empty)
Operation
push(1)
Result
-
Doubly Linked List (Stack)
TreeMap
5
1
← top
← bottom
5 (×1)
Operation
push(5)
Result
-
Doubly Linked List (Stack)
TreeMap
5
1
← top
← bottom
1 (×1)
5 (×1)
min
max
Operation
top()
Result
-
Doubly Linked List (Stack)
TreeMap
5
1
5
← top
← bottom
1 (×1)
5 (×2)
min
max
Operation
popMax()
Result
-
Doubly Linked List (Stack)
TreeMap
5
1
5
← top
← bottom
1 (×1)
5 (×2)
min
max
Operation
top()
Result
-
Doubly Linked List (Stack)
TreeMap
5
1
← top
← bottom
1 (×1)
5 (×1)
min
max
Operation
peekMax()
Result
5
Doubly Linked List (Stack)
TreeMap
5
1
← top
← bottom
1 (×1)
5 (×1)
min
max
Operation
pop()
Result
1
Doubly Linked List (Stack)
TreeMap
5
← top
← bottom
5 (×1)
Operation
Done
Result
-
Doubly Linked List (Stack)
TreeMap
5
← top
← bottom
5 (×1)
algo
master
.
io
Step:
Max Stack: supports push, pop, top, peekMax, and popMax in O(log n)
0 / 40
Input
Example 1
Example 2
Example 3
Custom
operations
=
[MaxStack, push, push, push, top, popMax, top, peekMax, pop, top]
,
values
=
[null, 5, 1, 5, null, null, null, null, null, null]
0 / 40
algo
master
.
io
Step:
Max Stack: supports push, pop, top, peekMax, and popMax in O(log n)