GoalScope — is_balanced (Qwen2.5-Coder-32B-Instruct) — hover a token to see the patched verbalization
↵
<code>↵
def is_balanced(root):↵
"""Helper function to check the height of the tree and determine if it's balanced."""↵
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 or abs(left_height - right_height) > 1:↵
return -1↵
return max(left_height, right_height) + 1↵
↵
return check_height(root) != -1↵
</code>