Complete the code to check if a node is null.
if (node == [1]) return 0;
We check if the node is null to handle the base case of recursion.
Complete the code to get the maximum of two integers.
int height = Math.[1](leftHeight, rightHeight) + 1;
We use Math.Max to get the larger height between left and right subtrees.
Fix the error in the condition to check balance difference.
if (Math.Abs(leftHeight - rightHeight) > [1]) return false;
The tree is balanced if the height difference is at most 1.
Fill both blanks to complete the recursive height calculation and balance check.
int leftHeight = [1](node.left); int rightHeight = [2](node.right);
We recursively call GetHeight to find heights of left and right subtrees.
Fill all three blanks to complete the balance check method with recursive calls and return statement.
bool [1](TreeNode node) { if (node == null) return true; int leftHeight = GetHeight(node.left); int rightHeight = GetHeight(node.right); if (Math.Abs(leftHeight - rightHeight) > 1) return false; return [2](node.left) && [3](node.right); }
The method IsBalanced recursively checks if left and right subtrees are balanced.
