Given a binary tree, find if it is height balanced or not.
A tree is height balanced if difference between heights of left and right subtrees is not more than one for all nodes of tree.
A height balanced tree
An unbalanced tree
The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains number of edges. The second line contains the connections between the nodes.
For each testcase, in a new line, print 0 or 1 accordingly.
You don't need to take input. Just complete the function isBalanced that takes node as parameter and returns true if the tree is balanced else returns false.
1 <= T <= 100
1 <= Number of nodes <= 100
0 <= Data of a node <= 1000
1 2 L 2 3 R
10 20 L 10 30 R 20 40 L 20 60 R
Testcase1: The tree is
The max difference in height of left subtree and right subtree is 2, which is greater than 1. Hence unbalanced.
Testcase2: The tree is
The max difference in height of left subtree and right subtree is 1. Hence unbalanced.