Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if both nodes are null, which means symmetry at this point.
DSA C#
if (root1 == null && root2 [1] null) return true;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong symmetry check.
Checking only one node for null.
✗ Incorrect
Both nodes being null means they are symmetric at this point, so we return true.
2fill in blank
mediumComplete the code to check if either node is null, which means asymmetry.
DSA C#
if (root1 == null || root2 [1] null) return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causes incorrect false returns.
Not checking both nodes properly.
✗ Incorrect
If one node is null and the other is not, trees are not symmetric, so return false.
3fill in blank
hardFix the error in comparing node values for symmetry.
DSA C#
if (root1.val [1] root2.val) return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causes wrong symmetry detection.
Comparing wrong node properties.
✗ Incorrect
If node values are not equal, trees are not symmetric, so return false.
4fill in blank
hardFill both blanks to recursively check left and right subtrees for symmetry.
DSA C#
return IsSymmetric(root1.[1], root2.[2]) && IsSymmetric(root1.[2], root2.[1]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same child nodes on both sides causes wrong checks.
Mixing up left and right nodes.
✗ Incorrect
We compare root1's left with root2's right and root1's right with root2's left for symmetry.
5fill in blank
hardFill all three blanks to complete the public method that starts the symmetry check.
DSA C#
public bool IsSymmetric(TreeNode root) {
if (root == null) return [1];
return IsSymmetric(root.[2], root.[3]);
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning false when root is null causes wrong result.
Swapping left and right in the recursive call.
✗ Incorrect
If root is null, tree is symmetric (true). Then check left and right subtrees for symmetry.
