Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA C++
ListNode* newNode = new ListNode([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' or 'carry' instead of the digit value.
Using an undefined variable like 'value'.
✗ Incorrect
The constructor of ListNode takes the value to store in the node. 'val' is the correct variable holding the digit.
2fill in blank
mediumComplete the code to move to the next node in the linked list l1.
DSA C++
if (l1 != nullptr) l1 = l1->[1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Using 'val' which is the data, not the pointer.
✗ Incorrect
To move forward in a singly linked list, we assign the pointer to its 'next' node.
3fill in blank
hardFix the error in the condition to check if there is a carry after addition.
DSA C++
if ([1] > 9) carry = 1; else carry = 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'carry' instead of 'sum'.
Checking 'val' which is the digit after modulo.
✗ Incorrect
The carry depends on whether the sum of digits is greater than 9. Checking 'sum' is correct.
4fill in blank
hardFill both blanks to correctly update the sum and digit values.
DSA C++
sum = (l1 ? l1->val : 0) + (l2 ? l2->val : 0) + [1]; digit = sum [2] 10;
Attempts:
3 left
💡 Hint
Common Mistakes
Using division instead of modulo for digit.
Not adding carry to sum.
✗ Incorrect
We add carry to the sum, then digit is sum modulo 10 to get the current digit.
5fill in blank
hardFill all three blanks to correctly link the new node and move the pointer.
DSA C++
current->next = new ListNode([1]); current = [2]; l1 = [3];
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning current to l1 instead of current->next.
Not checking if l1 is null before moving to next.
✗ Incorrect
We create a new node with 'digit', move current to current->next, and advance l1 safely.
