what iam doing wrong ??
Is balanced one testcase failing
hi ajay
can you please explain your logic behind the line written in main which relates to maximum and minimum
how it will be able to find if the tree is balanced or not
i got your point ,this is a wrong approach. so what should be the logic for this ???
The question says to find out whether a given binary tree is balanced or not. A non-empty binary tree T is balanced if:
- Left subtree of T is balanced
- Right subtree of T is balanced
- The difference between heights of left subtree and right subtree is not more than 1.
Also, an empty tree is balanced.
algorithm:
Get the height of left and right subtrees.
Return true if difference between heights is not more than 1 and left and right subtrees are balanced, otherwise return false.
1 Like
thank u so much ma’am .