Tap here to switch tabs
Problem
Submissions

Problem: Distribute Coins in Binary Tree

Try to solve the Distribute Coins in Binary Tree problem.

Statement

You are given the root of a binary tree with n nodes, where each node contains Node.val coins. There are n coins in total across the entire tree.

In a single move, you can select two adjacent nodes and transfer exactly 11 coin from one node to the other. A move can occur between a parent node and a child node in either direction.

Return the minimum number of moves required such that every node has exactly 11 coin.

Constraints:

  • The number of nodes in the tree is n.

  • 1≤1 \leq n ≤100\leq 100

  • 0≤0 \leq Node.val ≤\leq n

  • The sum of all Node.val is n.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Distribute Coins in Binary Tree

Try to solve the Distribute Coins in Binary Tree problem.

Statement

You are given the root of a binary tree with n nodes, where each node contains Node.val coins. There are n coins in total across the entire tree.

In a single move, you can select two adjacent nodes and transfer exactly 11 coin from one node to the other. A move can occur between a parent node and a child node in either direction.

Return the minimum number of moves required such that every node has exactly 11 coin.

Constraints:

  • The number of nodes in the tree is n.

  • 1≤1 \leq n ≤100\leq 100

  • 0≤0 \leq Node.val ≤\leq n

  • The sum of all Node.val is n.