0
0
DSA Javascriptprogramming~10 mins

Two Sum in BST in DSA Javascript - 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 Javascript
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 != instead of ===
Using assignment = instead of comparison ===
2fill in blank
medium

Complete the code to add a value to the set.

DSA Javascript
set.[1](root.val);
Drag options to blanks, or click blank then click option'
Apush
Binsert
Cappend
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() which is for arrays
Using insert() which is not a Set method
3fill in blank
hard

Fix the error in checking if the complement exists in the set.

DSA Javascript
if (set.[1](target - root.val)) return true;
Drag options to blanks, or click blank then click option'
Ahas
Bincludes
Cfind
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using contains() which is not a Set method
Using includes() which is for arrays
4fill in blank
hard

Fill both blanks to complete the recursive calls for left and right subtrees.

DSA Javascript
return dfs(root.[1], set, target) || dfs(root.[2], set, target);
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cchild
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like child or node
Calling dfs on the same child twice
5fill in blank
hard

Fill all three blanks to complete the main function that uses DFS and a set.

DSA Javascript
var findTarget = function(root, target) {
  const set = new Set();
  function dfs(node, set, target) {
    if (node [1] null) return false;
    if (set.[2](target - node.val)) return true;
    set.[3](node.val);
    return dfs(node.left, set, target) || dfs(node.right, set, target);
  }
  return dfs(root, set, target);
};
Drag options to blanks, or click blank then click option'
A===
Bhas
Cadd
D!==
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of === for null check
Using contains instead of has for set
Using push instead of add for set