Practice Distribute Coins in Binary Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree. In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent. Return the minimum number of moves required to make every node have exactly one coin.
Source: Distribute Coins in Binary Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [3,0,0]
2
# Example 2
root = [0,3,0]
3
Constraints
Related LeetCode Problems
Practice more problems similar to Distribute Coins in Binary Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.