Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the sum digit.
DSA Go
newNode := &ListNode{Val: [1], Next: nil}Attempts:
3 left
💡 Hint
Common Mistakes
Using sum / 10 instead of sum % 10, which gives the carry instead of the digit.
Adding 10 to sum which changes the value incorrectly.
✗ Incorrect
We use sum % 10 to get the digit to store in the current node because each node stores a single digit.
2fill in blank
mediumComplete the code to update the carry after adding two digits.
DSA Go
carry = [1]Attempts:
3 left
💡 Hint
Common Mistakes
Using modulo operator instead of division for carry.
Multiplying sum by 10 which is incorrect.
✗ Incorrect
Carry is the part of sum that goes to the next digit, which is sum divided by 10.
3fill in blank
hardFix the error in the loop condition to continue while there are nodes or carry.
DSA Go
for l1 != nil || l2 != nil || [1] != 0 {
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum instead of carry in the loop condition.
Using node pointers instead of carry.
✗ Incorrect
We continue the loop while carry is not zero to add the leftover carry digit.
4fill in blank
hardFill both blanks to add values from nodes or zero if node is nil.
DSA Go
x := 0 if l1 != nil { x = [1] } y := 0 if l2 != nil { y = [2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Next instead of Val which is a pointer, not a value.
Not checking for nil before accessing Val.
✗ Incorrect
We assign x and y the values of the current nodes if they exist, otherwise zero.
5fill in blank
hardFill all three blanks to move to the next nodes and link the new node.
DSA Go
current.Next = newNode current = [1] if l1 != nil { l1 = [2] } if l2 != nil { l2 = [3] }
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning current to newNode instead of current.Next.
Using newNode.Next instead of l1.Next or l2.Next.
Not advancing l1 or l2 pointers correctly.
✗ Incorrect
We move current to current.Next, and move l1 and l2 to their Next nodes if they exist.
