Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current node is null.
DSA Typescript
if (root [1] null) return null;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ===
Using assignment operator = instead of comparison
Checking for undefined instead of null
✗ Incorrect
We check if root is exactly equal to null to stop recursion.
2fill in blank
mediumComplete the code to check if the current node is either p or q.
DSA Typescript
if (root [1] p || root [1] q) return root;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ===
Using > or < which are not suitable for equality checks
✗ Incorrect
We compare root with p and q using strict equality.
3fill in blank
hardFix the error in the recursive calls to search left and right subtrees.
DSA Typescript
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
Swapping left and right
✗ Incorrect
The left subtree is accessed by root.left and the right subtree by root.right.
4fill in blank
hardFill both blanks to return the correct node based on left and right subtree results.
DSA Typescript
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 !==
Using logical OR instead of AND
✗ Incorrect
If both left and right are not null, the current root is the lowest common ancestor.
5fill in blank
hardFill the blank to return the non-null subtree or null if both are null.
DSA Typescript
return left [1] right;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using && which requires both to be true
Using equality operators which are not suitable here
✗ Incorrect
We use logical OR || to return the non-null subtree or null if both are null.