Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Distribute Coins in Binary Tree
Bookmark
Iterative Edge Flow
Post-Order DFS
Input
Example 1
Example 2
Example 3
Custom
tree
=
[3, 0, 0]
3
0
0
3 coins
0 coins
0 coins
moves
0
moves = coins crossing every edge, settled bottom-up
3
0
0
3 coins
0 coins
0 coins
moves
0
moves = coins crossing every edge, settled bottom-up
3
0
0
3 coins
0 coins
0 coins
moves
0
moves = coins crossing every edge, settled bottom-up
3
0
0
3 coins
0 coins
0 coins
moves
0
excess =
0
- 1 =
0
2
0
1
2 coins
0 coins
1 coin
moves
1
2
0
1
2 coins
0 coins
1 coin
moves
1
excess =
0
- 1 =
0
2
0
1
2 coins
0 coins
1 coin
moves
2
1
1
1
1 coin
1 coin
1 coin
moves
2
1
1
1
1 coin
1 coin
1 coin
moves
2
1
1
1
1 coin
1 coin
1 coin
moves
2
root has no parent edge:
1 coin
1
1
1
1 coin
1 coin
1 coin
moves
2
2 moves
algo
master
.
io
Step:
Start: move coins until every node holds exactly 1
0 / 11
Input
Example 1
Example 2
Example 3
Custom
tree
=
[3, 0, 0]
0 / 11
algo
master
.
io
Step:
Start: move coins until every node holds exactly 1