Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Remove K Digits
Bookmark
Brute Force
Greedy Stack
Input
Input 1
Input 2
Input 3
Custom
num
=
1432219
,
k
=
3
1
0
4
1
3
2
2
3
2
4
1
5
9
6
1
0
4
1
3
2
2
3
2
4
1
5
9
6
combination #3: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"1431"
best so far =
"1431"
new smallest!
combination #7: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"1429"
best so far =
"1421"
not smaller, keep the best
combination #11: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"1322"
best so far =
"1322"
new smallest!
combination #15: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"1329"
best so far =
"1321"
not smaller, keep the best
combination #20: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"1219"
best so far =
"1219"
not smaller, keep the best
combination #24: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"4321"
best so far =
"1219"
not smaller, keep the best
combination #28: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"4229"
best so far =
"1219"
not smaller, keep the best
combination #32: remove 3, keep 4
1
0
4
1
3
2
2
3
2
4
1
5
9
6
candidate =
"3229"
best so far =
"1219"
not smaller, keep the best
winning combination
1
0
4
1
3
2
2
3
2
4
1
5
9
6
smallest =
"1219"
algo
master
.
io
Step:
Brute force: try every way to keep n - k digits, take the smallest number.
0 / 37
Input
Input 1
Input 2
Input 3
Custom
num
=
1432219
,
k
=
3
0 / 37
algo
master
.
io
Step:
Brute force: try every way to keep n - k digits, take the smallest number.