Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the sum digit.
DSA Java
ListNode newNode = new ListNode([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using sum / 10 instead of sum % 10.
Adding 10 to sum instead of modulo operation.
✗ Incorrect
We use sum % 10 to get the digit to store in the new node because sum can be more than 9.
2fill in blank
mediumComplete the code to update the carry after adding two digits.
DSA Java
carry = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using sum % 10 for carry instead of sum / 10.
Adding 10 to sum instead of dividing.
✗ Incorrect
Carry is the tens digit of the sum, so we use integer division sum / 10.
3fill in blank
hardFix the error in the loop condition to continue while nodes or carry exist.
DSA Java
while (l1 != null || [1] != null || carry != 0) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking carry twice instead of l2.
Checking l1 twice instead of l2.
✗ Incorrect
We must check if l2 is not null to continue adding digits from the second list.
4fill in blank
hardFill both blanks to safely get values from nodes or zero if null.
DSA Java
int x = (l1 != null) ? [1] : 0; int y = (l2 != null) ? [2] : 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using .next instead of .val to get values.
Not checking for null before accessing values.
✗ Incorrect
We get the value from l1.val and l2.val if nodes exist; otherwise zero.
5fill in blank
hardFill all three blanks to move to the next nodes or keep null if none.
DSA Java
l1 = (l1 != null) ? [1] : null; l2 = (l2 != null) ? [2] : null; current = current.[3];
Attempts:
3 left
💡 Hint
Common Mistakes
Using .val instead of .next to move nodes.
Not updating current pointer correctly.
✗ Incorrect
We move l1 and l2 to their next nodes, and current to current.next to continue building the list.
