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 Typescript
if (root1 === null && root2 [1] null) { return true; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong symmetry check.
Using '>' or '<' operators here is incorrect.
✗ Incorrect
Both nodes being null means they are symmetric here, so we check if root2 is equal to null.
2fill in blank
mediumComplete the code to check if either node is null, which means trees are not symmetric.
DSA Typescript
if (root1 === null || root2 [1] null) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causes wrong symmetry detection.
Using '>' or '<' operators here is incorrect.
✗ Incorrect
If one node is null and the other is not, trees are not symmetric, so we check if root2 is not null.
3fill in blank
hardFix the error in comparing the values of the two nodes to check symmetry.
DSA Typescript
if (root1.val [1] root2.val) { return false; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causes wrong symmetry detection.
Using '>' or '<' operators here is incorrect.
✗ Incorrect
If the values are not equal, the trees are not symmetric, so we check if root1.val is not equal to root2.val.
4fill in blank
hardFill both blanks to recursively check the left subtree of root1 with the right subtree of root2 and vice versa.
DSA Typescript
return isSymmetricHelper(root1.[1], root2.[2]) && isSymmetricHelper(root1.right, root2.left);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right incorrectly.
Using 'val' or 'root' instead of child nodes.
✗ Incorrect
To check symmetry, compare root1's left with root2's right and root1's right with root2's left.
5fill in blank
hardFill all three blanks to define the helper function signature and call it from the main function.
DSA Typescript
function [1](root1: TreeNode | null, root2: TreeNode | null): boolean { // helper logic here } function [2](root: TreeNode | null): boolean { if (root === null) return true; return [3](root.left, root.right); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up function names.
Not calling the helper function from main.
✗ Incorrect
The helper function is named isSymmetricHelper, the main function is isSymmetric, and the main function calls isSymmetricHelper.