Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the BST node is null.
DSA Typescript
if (root [1] null) return false;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' causes wrong base case.
Using comparison operators like '>=' with null is incorrect.
✗ Incorrect
We check if root is exactly equal to null to stop recursion.
2fill in blank
mediumComplete the code to add a value to the set.
DSA Typescript
seenValues.[1](root.val); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'push' causes runtime error because Set has no push method.
Using 'append' or 'insert' are not valid Set methods.
✗ Incorrect
Sets use 'add' method to insert new elements.
3fill in blank
hardFix the error in checking if the complement exists in the set.
DSA Typescript
if (seenValues.[1](target - root.val)) return true;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' or 'includes' causes errors because Set does not have these methods.
Using 'find' returns element or undefined, not boolean.
✗ Incorrect
'has' is the correct method to check presence in a Set.
4fill in blank
hardFill both blanks to complete the recursive calls for left and right subtrees.
DSA Typescript
return dfs(root.[1], target, seenValues) || dfs(root.[2], target, seenValues);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent' causes undefined errors.
Using 'child' is not a valid property.
✗ Incorrect
We recursively search left and right children of the current node.
5fill in blank
hardFill all three blanks to complete the main function that starts DFS with an empty set.
DSA Typescript
function findTarget(root: TreeNode | null, target: number): boolean {
const seenValues = new Set<number>();
return dfs([1], [2], [3]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'null' instead of root causes immediate false return.
Passing wrong order of arguments causes runtime errors.
✗ Incorrect
We start DFS with root node, target number, and empty set.