Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with a given value.
DSA Rust
let new_node = ListNode::new([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' or 'head' instead of the value.
Forgetting to pass any argument.
✗ Incorrect
The new node is created with the given value 'val'.
2fill in blank
mediumComplete the code to advance the pointer to the next node.
DSA Rust
current = current[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using '.prev' which is for doubly linked lists.
Using '.value' which holds data, not the next node.
✗ Incorrect
To move forward in the list, use '.next' to get the next node.
3fill in blank
hardFix the error in the loop condition to check if pointers are not null.
DSA Rust
while [1].is_some() && [2].is_some() {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the same pointer twice.
Using undefined variables.
✗ Incorrect
Both pointers must be checked separately; here, the first pointer is checked twice by mistake.
4fill in blank
hardFill both blanks to compare node pointers and advance the correct pointer.
DSA Rust
if ptr1 == ptr2 { return ptr1; } else if ptr1[1] < ptr2[2] { ptr1 = ptr1.unwrap().next.clone(); } else { ptr2 = ptr2.unwrap().next.clone(); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.unwrap()' which moves ownership and causes errors.
Using '.clone()' unnecessarily.
✗ Incorrect
To compare the nodes, use '.as_ref()' to get references without moving ownership.
5fill in blank
hardFill all three blanks to return None if no intersection is found after traversal.
DSA Rust
while ptr1.is_some() && ptr2.is_some() { if ptr1 == ptr2 { return ptr1; } ptr1 = ptr1.unwrap().next.clone(); ptr2 = ptr2.unwrap().next.clone(); } return [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a new node instead of None.
Returning one of the pointers without intersection.
✗ Incorrect
If no intersection is found, the function returns 'None' to indicate no shared node.
