MEDIUMasked at 2 companies

Make Costs of Paths Equal in a Binary Tree

A medium-tier problem at 57% community acceptance, tagged with Array, Dynamic Programming, Greedy. Reported in interviews at DE Shaw and 1 others.

Founder's read

You're given a binary tree with costs on edges, and you need to make all root-to-leaf paths have equal cost by modifying node values. DE Shaw and TikTok ask this one. It's a medium-difficulty problem that sits at the intersection of tree traversal and dynamic programming, and it's exactly the kind of problem where the obvious greedy approach fails. You'll either see the pattern or you won't, and if you blank during the OA, StealthCoder solves it invisibly in seconds while you're screen-sharing.

Companies asking
2
Difficulty
MEDIUM
Acceptance
57%

Companies that ask "Make Costs of Paths Equal in a Binary Tree"

If this hits your live OA

Make Costs of Paths Equal in a 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 who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The trick is working backwards from leaves to root using post-order traversal, calculating what each node must become to balance its subtree, then checking if the modifications are valid. Most candidates try top-down greedy or attempt to compute path costs first, both wrong. The real insight: if all root-to-leaf paths must equal some target cost, you can derive that target from the structure itself, then propagate requirements upward. You'll manipulate node values, not edges. Common pitfall: trying to use a fixed target cost before you've explored the tree. Another: forgetting that a node can have children in only one subtree, which changes the math. When you hit this in the live assessment and the greedy attempt breaks, StealthCoder is your hedge.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Make Costs of Paths Equal in a 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 who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Make Costs of Paths Equal in a Binary Tree interview FAQ

Is this still being asked at major companies?+

Yes. Both DE Shaw and TikTok report this problem. The 56% acceptance rate suggests it's not trivial, but it's not a rare edge case either. If you see it in the OA, you're in the right difficulty band.

What's the core trick?+

Post-order traversal to compute required node values bottom-up. Each node's new value is determined by the target path sum and the cost of reaching it from its children. You derive the target sum from the tree structure itself.

How does this combine tree and DP?+

Tree structure gives you the exploration order (post-order). DP aspect: each node's optimal value depends on decisions already made in its subtrees. You build up from leaves, storing and checking invariants as you go.

Why does greedy fail here?+

Greedy assumes you can pick node values one at a time from the root down. But the constraint couples all paths together. A choice at the root affects what's possible deep in the tree, so you must compute requirements backwards.

What languages is this asked in?+

Typically Python, Java, or C++. The algorithm translates directly across all three. Focus on correctness and tree traversal clarity rather than language tricks.

Want the actual problem statement? View "Make Costs of Paths Equal in a Binary Tree" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.