Distribute Coins in Binary Tree
A medium-tier problem at 77% community acceptance, tagged with Tree, Depth-First Search, Binary Tree. Reported in interviews at PhonePe and 0 others.
Distribute Coins in Binary Tree is the kind of problem that looks straightforward until you realize the greedy approach doesn't work. You're given a binary tree where each node has some coins, and the goal is to redistribute coins so every node ends up with exactly one. The catch: moving a coin between adjacent nodes costs one coin. PhonePe has asked this one. It's a medium-difficulty tree problem that trips up candidates who don't think bottom-up. If you hit this live and freeze on the movement cost logic, StealthCoder solves it invisibly while you stay calm.
Companies that ask "Distribute Coins in Binary Tree"
Distribute Coins in Binary Tree is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe trick here is post-order traversal with a balance-tracking approach. Most people try to solve it greedily top-down or get lost in the movement mechanics. What actually works: process the tree from the leaves up, track how many coins each subtree needs or has in excess, and calculate the cost of moving coins up to the parent. Each node should end up with exactly one coin after redistribution. The real insight is that you can't decide what to do at a parent until you know the state of both children. Common failure: forgetting that moving a coin from child to parent, or between siblings through the parent, each costs moves. DFS with a return value representing net coin flow (excess or deficit) is the pattern. If this problem appears in your assessment and you're unsure of the movement cost accounting, StealthCoder handles the traversal logic and gives you a working solution in seconds.
Pattern tags
You know the problem.
Make sure you actually pass it.
Distribute Coins in Binary Tree recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Distribute Coins in Binary Tree interview FAQ
Is this really asked by major companies, or just obscure platforms?+
PhonePe has reported it, which is a significant fintech name. The acceptance rate sits at 77%, so it's not a rare edge case. It's positioned as a medium, suggesting it shows up in later-round technical screens rather than initial filters.
What's the actual trick I need to know before the interview?+
You must process the tree bottom-up using post-order DFS. Track the excess or deficit of coins at each node as you return from children. The movement cost is the absolute value of coins that need to flow upward. This isn't a simple tree traversal; it's about accounting for redistribution flow.
How does this relate to other tree problems I've drilled?+
It combines standard binary tree DFS with a constraint-satisfaction layer. Unlike simple path-sum or counting problems, you're balancing state at every node. If you've done problems on Tree DP or node-to-node transfer, this feels similar but the movement cost mechanic is the new wrinkle.
Is there a greedy or math shortcut I'm missing?+
No. You need DFS and explicit tracking. The problem deliberately makes greedy fail because movement cost depends on tree depth and structure. There's no formula or closed-form answer; you must simulate the traversal.
How much time should I spend on this if I see it live?+
If you know the post-order DFS pattern, 20 to 30 minutes to code and debug. If you don't recognize the pattern immediately, you risk running over. That's where having a safety net matters. Most candidates spend 40 to 50 minutes or bail. Know the approach before the OA.
Want the actual problem statement? View "Distribute Coins in Binary Tree" on LeetCode →