Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Last Stone Weight
Bookmark
Input
Example 1
Single Stone
Pairs Cancel
Custom
stones
=
[2, 7, 4, 1, 8, 1]
2
7
4
1
8
1
smash the two heaviest stones until at most one remains
2
7
4
1
8
1
smash the two heaviest stones until at most one remains
stones left =
6
round =
1
y
x
2
7
4
1
8
1
y = pop max =
8
stones left =
6
round =
1
y
x
2
7
4
1
8
1
x = pop max =
7
stones left =
5
round =
2
y
x
2
4
1
1
1
y = pop max =
4
stones left =
5
round =
2
y
x
2
4
1
1
1
x = pop max =
2
stones left =
4
round =
3
y
x
1
1
1
2
y = pop max =
2
stones left =
4
round =
3
y
x
1
1
1
2
x = pop max =
1
stones left =
3
round =
4
y
x
1
1
1
y = pop max =
1
stones left =
3
round =
4
y
x
1
1
1
x = pop max =
1
stones left =
1
1
Last stone weight = 1
algo
master
.
io
Step:
Start: stones = [2, 7, 4, 1, 8, 1]
0 / 14
Input
Example 1
Single Stone
Pairs Cancel
Custom
stones
=
[2, 7, 4, 1, 8, 1]
0 / 14
algo
master
.
io
Step:
Start: stones = [2, 7, 4, 1, 8, 1]