Implemented a solution to check whether a tree is balanced