Question: 
Write a function to check if a binary tree is balanced or not.


Model's Code:
def is_tree_balanced(root):
    def check_height(node):
        if not node:
            return 0
        left_height = check_height(node.left)
        if left_height == -1:
            return -1
        right_height = check_height(node.right)
        if right_height == -1:
            return -1
        if abs(left_height - right_height) > 1:
            return -1
        return max(left_height, right_height) + 1

    return check_height(root) != -1



Sample Correct Code:
class Node: 
	def __init__(self, data): 
		self.data = data 
		self.left = None
		self.right = None
def get_height(root): 
	if root is None: 
		return 0
	return max(get_height(root.left), get_height(root.right)) + 1
def is_tree_balanced(root): 
	if root is None: 
		return True
	lh = get_height(root.left) 
	rh = get_height(root.right) 
	if (abs(lh - rh) <= 1) and is_tree_balanced( 
	root.left) is True and is_tree_balanced( root.right) is True: 
		return True
	return False


Asserts:
assert is_tree_balanced(root) == False
assert is_tree_balanced(root1) == True
assert is_tree_balanced(root2) == False 


Tests:
Test 1 of 3: FAIL: NameError("name 'root' is not defined")

Test 367 of 974: 265/367 (72.20708446866485%): failed