Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if two nodes are both null.
DSA Javascript
if (node1 === null && node2 [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 logic.
Using !== between node2 and null instead of ===.
✗ Incorrect
We check if both nodes are null using the strict equality operator (===).
2fill in blank
mediumComplete the code to check if one node is null and the other is not.
DSA Javascript
if (node1 === null || node2 [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 detection.
Using logical operators instead of comparison operators.
✗ Incorrect
We check if one node is null and the other is not using !==.
3fill in blank
hardFix the error in comparing node values for symmetry.
DSA Javascript
if (node1.val [1] node2.val) return false;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using === causes wrong logic because it returns false when values differ.
Using < or > is incorrect for equality check.
✗ Incorrect
If the values are not equal (!==), the trees are not symmetric.
4fill in blank
hardFill both blanks to recursively check left and right subtrees for symmetry.
DSA Javascript
return isSymmetricHelper(node1.[1], node2.[2]) && isSymmetricHelper(node1.[2], node2.[1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'val' or 'parent' instead of 'left' or 'right' causes errors.
Swapping left and right incorrectly breaks symmetry check.
✗ Incorrect
We compare node1's left with node2's right and node1's right with node2's left.
5fill in blank
hardFill all three blanks to define the main function calling the helper.
DSA Javascript
function isSymmetric(root) {
if (root === null) return true;
return isSymmetricHelper(root.[1], root.[2]);
}
function isSymmetricHelper(node1, node2) {
if (node1 === null && node2 === null) return true;
if (node1 === null || node2 === null) return false;
if (node1.val [3] node2.val) return false;
return isSymmetricHelper(node1.left, node2.right) && isSymmetricHelper(node1.right, node2.left);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using === instead of !== for value comparison.
Swapping left and right in the main function call.
✗ Incorrect
The main function compares root.left and root.right, and the helper checks if values differ using !==.