Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the sum digit.
DSA Rust
let new_node = ListNode::new([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using sum / 10 instead of sum % 10.
Adding carry directly without modulo.
✗ Incorrect
We use sum % 10 to get the digit to store in the new node because the sum can be more than 9.
2fill in blank
mediumComplete the code to update the carry after adding two digits.
DSA Rust
carry = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using modulo instead of division for carry.
Adding carry again instead of updating it.
✗ Incorrect
Carry is the tens digit of the sum, so we divide sum by 10 to get it.
3fill in blank
hardFix the error in the loop condition to continue while there are digits or carry.
DSA Rust
while l1.is_some() || l2.is_some() || [1] > 0 {
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum instead of carry in the condition.
Checking new_node or result which are not loop conditions.
✗ Incorrect
We continue the loop while carry is greater than 0 to add any leftover carry digit.
4fill in blank
hardFill both blanks to move to the next nodes in the lists if they exist.
DSA Rust
l1 = if let Some(node) = l1 { [1] } else { [2] }; l2 = if let Some(node) = l2 { [1] } else { [2] };
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning node instead of node.next.
Using Some(node) instead of None when no next node.
✗ Incorrect
We move to the next node using node.next, or None if no next node exists.
5fill in blank
hardFill all three blanks to build the result list and update the current pointer.
DSA Rust
sum = [2] + [3] + carry; current.next = Some(Box::new(ListNode::new([1]))); current = current.next.as_mut().unwrap();
Attempts:
3 left
💡 Hint
Common Mistakes
Using carry instead of sum % 10 for the new node value.
Mixing up l1_val and l2_val in sum calculation.
✗ Incorrect
We first calculate sum by adding l1_val, l2_val, and carry, then create a new node with sum % 10.
