easyTreesGoogleAmazonBloomberg
Silo Balance Monitor
A silo inventory router checks whether storage structures have evenly balanced bins to distribute physical load safely.
Given a binary tree, determine if it is height-balanced (heights of left and right of every node differ by at most 1).
Choose approach
3
curr
9
20
15
7
1/11
Narrationstep 1 of 11
Validate node 3. Check left & right subtrees balance status.
Variables
curr=3
How to think about it
- Height of empty tree is 0.
- Evaluate each node's left and right heights recursively.
- Bubble up -1 on structural imbalance, which prevents wasteful overhead on further branches.
Edge cases to catch in interview
- Empty tree -> balanced.
- Deeply left-skewed or right-skewed tree -> false.
Examples
Example 1
true{"arr":[3,9,20,null,null,15,7]}
Example 2
false{"arr":[1,2,2,3,3,null,null,4,4]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed