Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Binary Tree but will also help you build up problem-solving skills.
In this problem, we are given, a binary tree, to find if it is height-balanced or not.
A tree is height-balanced if the difference between the heights of left and right subtrees is not more than one for all nodes of the tree.
Example :
Input:
1
/
2
\
3
Output: 0
Explanation: The max difference in height of the left subtree and right subtree is 2, which is greater than 1. Hence unbalanced
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/check-for-balanced-tree/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/b4d0bdb1-df21-44e6-b8da-6f1ccc96a1d6