Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current node is null.
DSA Javascript
if (root [1] null) return null;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' causes wrong logic.
Using '>' or '<' to compare with null is incorrect.
✗ Incorrect
We check if root is exactly equal to null to stop recursion when we reach a leaf's child.
2fill in blank
mediumComplete the code to check if the current node matches either of the target nodes p or q.
DSA Javascript
if (root.val [1] p.val || root.val [1] q.val) return root;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' causes wrong logic.
Using loose equality '==' can cause bugs.
✗ Incorrect
We use strict equality '===' to check if the current node's value matches p or q.
3fill in blank
hardFix the error in the recursive calls to search left and right subtrees.
DSA Javascript
const left = lowestCommonAncestor(root.[1], p, q); const right = lowestCommonAncestor(root.[2], p, q);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like leftChild or rightChild.
Recursing on the same subtree twice.
✗ Incorrect
We must recurse on root.left and root.right to search both subtrees.
4fill in blank
hardFill both blanks to return the correct ancestor based on left and right subtree results.
DSA Javascript
if (left [1] null && right [2] null) return root;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '===' instead of '!==' causes wrong condition.
Using logical OR '||' instead of AND '&&' changes logic.
✗ Incorrect
If both left and right are not null, root is the lowest common ancestor.
5fill in blank
hardFill the blanks to return the non-null subtree result or null.
DSA Javascript
return left [1] right ? left [2] right : null;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' instead of '||' changes the logic.
Using '===' instead of '!==' causes wrong checks.
✗ Incorrect
Return left if left is not null; otherwise return right if right is not null; else null.