Solution to check if tree is balanced