← Back
00:00

Balanced Drainage Split

Two Sigma interview questions · Medium · OA round · 6 tests

You are given a rooted tree representing a water-drainage network. Nodes are labeled 0 through n - 1, and node 0 is the root. Water enters the system at every node and then flows upward toward the root.

The tree is described by:

  • parent[i]: the parent of node i, with parent[0] = -1
  • input[i]: the amount of water entering at node i
Idle