r/badcode • • Jun 19 '21

typescript Check if binary tree is balanced...

Post image
221 Upvotes

44 comments sorted by

View all comments

137

u/SuperSmurfen Jun 19 '21 edited Jun 19 '21

What is bad about this? Looks pretty readable to me, good variable names (all though perhaps a bit verbose), and it's pretty much just the standard O(n) algorithm

www.geeksforgeeks.org/how-to-determine-if-a-binary-tree-is-balanced

-55

u/MrPancholi Jun 19 '21

It does work, but I just thought that the tuple thing I did was a little weird.

I suck with algorithms so I though this was pretty far form the ideal solution.

3

u/btwiusearch Jun 19 '21
getHeightBalanceTupl

The weird thing is that the e is missing.