Complete the code to count nodes by returning 1 plus counts of left and right subtrees.
def count_nodes(root): if root is None: return 0 return 1 + count_nodes(root.[1]) + count_nodes(root.right)
We count the current node (1) plus nodes in the left subtree (root.left) and right subtree (root.right).
Complete the code to check if the tree is empty by comparing root to {{BLANK_1}}.
def count_nodes(root): if root == [1]: return 0 return 1 + count_nodes(root.left) + count_nodes(root.right)
We check if root is None to know if the tree or subtree is empty.
Fix the error in the recursive call to count nodes in the right subtree.
def count_nodes(root): if root is None: return 0 return 1 + count_nodes(root.left) + count_nodes(root.[1])
The correct attribute for the right child is root.right.
Fill both blanks to complete the dictionary comprehension that maps each node's value to its subtree size if the value is greater than 10.
sizes = {node.val: count_nodes(node) for node in nodes if node.val [1] 10 and node.[2] is not None}We want nodes with value greater than 10 and check if left child exists (node.left is not None).
Fill both blanks to create a dictionary mapping uppercase node values to their counts if count is greater than 1.
result = {node.val[1]: count for node, count in counts.items() if count [2] 1 and node.val is not None}We convert node.val to uppercase with .upper(), check count > 1, and ensure node.val is not None (empty string means no change).
