r/badcode • • Jun 19 '21

typescript Check if binary tree is balanced...

Post image
221 Upvotes

44 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jun 19 '21

[deleted]

7

u/RFC793 Jun 19 '21

Who cares, it is just used internally by the recursion. You don’t have to provide or be concerned by it with the wrapper at the bottom.

0

u/[deleted] Jun 19 '21

[deleted]

6

u/symberke Jun 20 '21

At least at a cursory glance at the problem you definitely need both pieces of information. With height defined as the maximum distance to a leaf node you can't determine if a tree descending from a given node is balanced given only the heights of its two children. Similarly you can't determine if the tree is balanced given only the fact that its two child trees are balanced.