Skip to content

979. Distribute Coins in Binary Tree #204

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

The problem requires redistributing coins in a binary tree such that each node ends up with exactly one coin. You are given a binary tree with n nodes, where each node contains a certain number of coins. The goal is to determine the minimum number of moves needed to ensure every node has exactly one coin. A move consists of transferring a coin between adjacent nodes, either from a parent to a child or vice versa.

Key Points

  1. Tree structure: A binary tree is given with n nodes.
  2. Node coins: Each node may have a number of coins.
  3. Moves: A move consists of transferring one coin between adjacent nodes.
  4. Objective: Minimize the number of moves to ensure each node has exactly one coin.

Approach

T…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Dec 30, 2024
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants