Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Apple Redistribution into Boxes
Bookmark
Brute Force
Greedy + Sorting
Input
Example 1
Example 2
Single apple pack
Fewer boxes
Custom
apple
=
[1, 3, 2]
,
capacity
=
[4, 3, 1, 5, 2]
apple
packs
capacity
boxes
1
3
2
0
1
2
3
4
4
3
1
5
2
apple
packs
capacity
boxes
1
3
2
0
1
2
3
4
4
3
1
5
2
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 1
·
sum =
0
<
6
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
4
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 1
·
sum =
4
<
6
boxes [0]
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
1
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 1
·
sum =
1
<
6
boxes [2]
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
5
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 1
·
sum =
5
<
6
boxes [3]
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
2
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 1
·
sum =
2
<
6
boxes [4]
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 1
·
sum =
0
<
6
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
4
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 2
·
sum =
4
<
6
boxes [0]
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
4
3
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
i
size 2
·
sum =
7
≥
6
boxes [0, 1]
boxes =
2
totalApples =
6
apple
packs
capacity
boxes
4
3
totalApples
1
3
2
0
1
2
3
4
4
3
1
5
2
7
≥
6
→ return boxes =
2
algo
master
.
io
Step:
Start: try every subset of boxes, smallest first, until one holds all the apples.
0 / 20
Input
Example 1
Example 2
Single apple pack
Fewer boxes
Custom
apple
=
[1, 3, 2]
,
capacity
=
[4, 3, 1, 5, 2]
0 / 20
algo
master
.
io
Step:
Start: try every subset of boxes, smallest first, until one holds all the apples.