Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Fair Distribution of Cookies
Bookmark
Backtracking
With Pruning
Bitmask DP
Input
Standard
Small
Simple
Custom
cookies
=
[8, 15, 10, 20, 8]
,
k
=
2
cookie bags
8
15
10
20
8
0
child 0
0
child 1
best unfairness = -
cookie bags
8
15
10
20
8
0
child 0
0
child 1
best unfairness = -
cookie bags
8
15
10
20
8
33
child 0
20
child 1
best unfairness = 41
take the bag back from child 0
cookie bags
8
15
10
20
8
31
child 0
30
child 1
best unfairness = 31
unfairness = 31
cookie bags
8
15
10
20
8
18
child 0
35
child 1
best unfairness = 31
bag 4 holds 8 cookies
cookie bags
8
15
10
20
8
8
child 0
45
child 1
best unfairness = 31
child 1 takes 20
cookie bags
8
15
10
20
8
45
child 0
8
child 1
best unfairness = 31
take the bag back from child 0
cookie bags
8
15
10
20
8
43
child 0
18
child 1
best unfairness = 31
unfairness = 43
cookie bags
8
15
10
20
8
30
child 0
23
child 1
best unfairness = 31
bag 4 holds 8 cookies
cookie bags
8
15
10
20
8
20
child 0
33
child 1
best unfairness = 31
child 0 takes 20
cookie bags
8
15
10
20
8
0
child 0
0
child 1
best unfairness = 31
minimum unfairness = 31
algo
master
.
io
Step:
Hand 5 cookie bag(s) to 2 child(ren) so the largest share is as small as possible
0 / 221
Input
Standard
Small
Simple
Custom
cookies
=
[8, 15, 10, 20, 8]
,
k
=
2
0 / 221
algo
master
.
io
Step:
Hand 5 cookie bag(s) to 2 child(ren) so the largest share is as small as possible