Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the BST node is null.
DSA C#
if (root [1] null) return false;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong logic.
Using comparison operators like '<=' or '>' with null is invalid.
✗ Incorrect
We check if the current node is null using '== null' to stop recursion.
2fill in blank
mediumComplete the code to add a value to the HashSet.
DSA C#
set.[1](root.val);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Contains' checks existence but does not add.
Using 'Remove' deletes elements, which is incorrect here.
✗ Incorrect
We add the current node's value to the set using 'Add'.
3fill in blank
hardFix the error in the condition to check if complement exists in the set.
DSA C#
if (set.[1](target - root.val)) return true;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Add' instead of 'Contains' causes wrong logic.
Using 'Remove' or 'Clear' is incorrect here.
✗ Incorrect
We use 'Contains' to check if the complement value exists in the set.
4fill in blank
hardFill both blanks to recursively search left and right subtrees.
DSA C#
return TwoSumBST(root.[1], target, set) || TwoSumBST(root.[2], target, set);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent' or 'root' properties which do not exist causes errors.
Checking only one side misses possible pairs.
✗ Incorrect
We recursively check left and right child nodes to find the pair.
5fill in blank
hardFill all three blanks to complete the TwoSumBST method signature and initial call.
DSA C#
public bool TwoSumBST(TreeNode [1], int [2]) { var set = new HashSet<int>(); return TwoSumBST([3], [2], set); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' instead of 'target' confuses the target sum.
Using 'this.root' inside the method signature is invalid.
✗ Incorrect
The method takes 'root' and 'target' as parameters, and calls the helper with 'root' and 'target'.
