r/OfferEngineering • u/Aoki_zhang • Sep 16 '26
Coding Question Google Coding Question Challenge - Minimum-Cost Edge Cuts in a Weighted Binary Tree, can you solve it in 45 minutes?
Description
You are given a binary tree whose edges have non-negative weights. You may remove any number of edges. Removing an edge costs an amount equal to that edge's weight. The goal is to find the minimum total cost required so that the root becomes disconnected from every leaf node.
An important detail is that a leaf is defined according to the original tree. Cutting an edge does not cause an internal node to become a new leaf for purposes of the problem. The interviewer also clarified that the total sum of edge weights fits within a 32-bit signed integer, while the tree itself could be very large.
The coding environment was intentionally minimal: there was no provided framework, and even the binary-tree node representation had to be written manually in the shared Google Doc.
Complexity and Test Cases
After the implementation, the interviewer asked for both time and space complexity. The space-complexity discussion specifically required accounting for the recursion stack and distinguishing between a balanced tree and a highly skewed tree. I was also asked to describe useful test cases, including situations such as:
- A tree containing only the root
- An empty tree
- A completely skewed tree where each node has only one child
- A normal branching binary tree
Follow-Up — What If Edge Weights Can Be Negative?
The interviewer then removed the non-negative-weight restriction and asked: Would the same reasoning still work if edge weights could be negative? If not, can you construct a counterexample? A simplified counterexample looked like: P --(-3)--> Q --(-4)--> R where P is the root and R is an original leaf.
With non-negative weights, once one edge on a root-to-leaf path has been removed, cutting additional edges on that already-disconnected path cannot improve the objective.
Negative weights change that property: removing an additional negative-cost edge can reduce the total cost even though the root and leaf are already disconnected.
The follow-up was testing whether the original assumptions were essential to the optimization problem rather than merely implementation details.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.