Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Apple Redistribution into Boxes
Bookmark
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
totalApples =
6
apple
packs
capacity
boxes
1
3
2
0
1
2
3
4
4
3
1
5
2
totalApples =
1 + 3 + 2
=
6
totalApples =
6
apple
packs
capacity
boxes
totalApples
1
3
2
0
1
2
3
4
5
4
3
2
1
sort
capacity
in descending order
boxes =
0
totalApples =
6
apple
packs
capacity
boxes
totalApples
1
3
2
0
1
2
3
4
5
4
3
2
1
i
boxes =
0
, currentCapacity =
0
boxes =
1
totalApples =
6
apple
packs
capacity
boxes
5
totalApples
1
3
2
0
1
2
3
4
5
4
3
2
1
i
currentCapacity =
0
+
5
=
5
, boxes =
1
boxes =
1
totalApples =
6
apple
packs
capacity
boxes
5
totalApples
1
3
2
0
1
2
3
4
5
4
3
2
1
i
5
<
6
→ need more boxes
boxes =
2
totalApples =
6
apple
packs
capacity
boxes
5
4
totalApples
1
3
2
0
1
2
3
4
5
4
3
2
1
i
currentCapacity =
5
+
4
=
9
, boxes =
2
boxes =
2
totalApples =
6
apple
packs
capacity
boxes
5
4
totalApples
1
3
2
0
1
2
3
4
5
4
3
2
1
i
9
≥
6
→ return boxes =
2
boxes =
2
totalApples =
6
apple
packs
capacity
boxes
5
4
totalApples
1
3
2
0
1
2
3
4
5
4
3
2
1
Minimum boxes =
2
algo
master
.
io
Step:
Start: Find the minimum number of boxes that hold all apples
0 / 8
Input
Example 1
Example 2
Single apple pack
Fewer boxes
Custom
apple
=
[1, 3, 2]
,
capacity
=
[4, 3, 1, 5, 2]
0 / 8
algo
master
.
io
Step:
Start: Find the minimum number of boxes that hold all apples