0
0
DSA Typescriptprogramming~10 mins

Two Sum in BST in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A===
B!==
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' instead of '===' causes wrong base case.
Using comparison operators like '>=' with null is incorrect.
2fill in blank
medium

Complete 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'
Aappend
Badd
Cpush
Dinsert
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.
3fill in blank
hard

Fix 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'
Aincludes
Bcontains
Chas
Dfind
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.
4fill in blank
hard

Fill 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'
Aleft
Bright
Cparent
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent' causes undefined errors.
Using 'child' is not a valid property.
5fill in blank
hard

Fill 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'
Aroot
Btarget
CseenValues
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'null' instead of root causes immediate false return.
Passing wrong order of arguments causes runtime errors.