Is my code correct?

I created a function to check balanced height and it is creating correct output which is definitely not same as prateek bhaiya’s code!!
So, I want you to check whether it is correct or not!!

hi @subham221

your approach is NOT correct

binary tree T is balanced if:

  1. Left subtree of T is balanced
  2. Right subtree of T is balanced
  3. The difference between heights of left subtree and right subtree is not more than 1.

you have check only one condition

for input:
1 2 3 4 -1 -1 -1 -1 5 -1 6 -1 7 -1 -1
your code’s output is Balanced
but clearly it is Unbalanced

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course