Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current node is a leaf node.
DSA Rust
if node.left.is_none() && node.[1].is_none() {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking only one child instead of both.
Using incorrect field names like 'child' or 'parent'.
✗ Incorrect
A leaf node has no left or right children, so both must be None.
2fill in blank
mediumComplete the code to subtract the current node's value from the target sum.
DSA Rust
let remaining_sum = target_sum - node.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'data' which are not defined in this struct.
Using 'key' which is unrelated.
✗ Incorrect
The node's value is stored in the 'val' field in this tree structure.
3fill in blank
hardFix the error in the recursive call to check left subtree.
DSA Rust
if let Some(left_node) = &node.[1] { if has_path_sum(left_node, remaining_sum) { return true; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' for left subtree.
Using undefined fields like 'child' or 'parent'.
✗ Incorrect
To check the left subtree, we must access the 'left' child node.
4fill in blank
hardFill both blanks to check the right subtree recursively and return true if path found.
DSA Rust
if let Some([1]_node) = &node.[2] { if has_path_sum([1]_node, remaining_sum) { return true; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'left' and 'right' in variable and field names.
Using undefined field names.
✗ Incorrect
We name the variable 'right_node' and access the 'right' child to check the right subtree.
5fill in blank
hardFill all three blanks to complete the function signature and return false if no path found.
DSA Rust
fn [1](node: &Option<Box<TreeNode>>, [2]: i32) -> bool { if node.is_none() { return [3]; } // function body continues...
Attempts:
3 left
💡 Hint
Common Mistakes
Returning true when node is None.
Using wrong parameter names or function names.
✗ Incorrect
The function is named 'has_path_sum', takes 'target_sum' as parameter, and returns false if node is None.
