← Questions

Print each tree node's level and whether it is balanced

0
NetflixCodingLast asked Aug 2026

Given a tree, walk it with a depth-first search and report, for every node, its level and whether the subtree under it is balanced (by the definition the interviewer gives, such as child heights or subtree sums differing by at most a limit). The statement is long, so pin down the input format and the exact balance rule first, compute what you need bottom-up in one pass, and test your own code.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding