Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the previous pointer to None.
DSA Rust
let mut prev = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Setting prev to head instead of None.
Using Some(...) incorrectly for prev initialization.
✗ Incorrect
We start with prev as None because initially there is no previous node.
2fill in blank
mediumComplete the code to move the current pointer to the next node.
DSA Rust
let next = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access next directly without as_mut().
Using clone() instead of take(), which copies the list.
✗ Incorrect
We use as_mut(), unwrap(), and take() to safely extract the next node by moving ownership without cloning.
3fill in blank
hardFix the error in assigning current's next to prev.
DSA Rust
current.as_mut().unwrap().next = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning next instead of prev.
Using prev.clone() causing ownership issues.
✗ Incorrect
We assign prev directly to current's next to reverse the link.
4fill in blank
hardFill both blanks to update prev and current pointers correctly.
DSA Rust
prev = [1]; current = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping prev and current incorrectly.
Assigning prev to next instead of current.
✗ Incorrect
After reversing the link, prev moves to current, and current moves to next.
5fill in blank
hardFill all three blanks to complete the iterative reverse function.
DSA Rust
pub fn reverse_list(mut head: Option<Box<Node>>) -> Option<Box<Node>> {
let mut prev = [1];
let mut current = head;
while current.is_some() {
let next = current.as_mut().unwrap().next.take();
current.as_mut().unwrap().next = [2];
prev = [3];
current = next;
}
prev
}Attempts:
3 left
💡 Hint
Common Mistakes
Incorrect initialization of prev.
Wrong assignment of current's next pointer.
Not updating prev and current correctly.
✗ Incorrect
Initialize prev as None, assign prev to current's next, then move prev to current.
