Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the sum value.
DSA Javascript
let newNode = new ListNode([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using sum + 10 or sum * 10 instead of modulo causes wrong digit storage.
Forgetting to use modulo leads to nodes storing numbers greater than 9.
✗ Incorrect
We use sum % 10 to get the digit to store in the node because each node stores a single digit.
2fill in blank
mediumComplete the code to update the carry for the next addition.
DSA Javascript
carry = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using sum % 10 for carry is wrong because it gives the digit, not the carry.
Using sum * 10 or sum + 1 causes incorrect carry values.
✗ Incorrect
Carry is the tens digit of sum, so we use Math.floor(sum / 10) to get it.
3fill in blank
hardFix the error in the loop condition to continue while nodes or carry exist.
DSA Javascript
while (l1 !== null || [1] !== null || carry !== 0) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking l1 twice instead of l2 causes missing nodes from second list.
Checking carry or sum incorrectly in place of l2 causes logic errors.
✗ Incorrect
We check l2 !== null to continue if the second list still has nodes.
4fill in blank
hardFill both blanks to safely get values from nodes or use 0 if null.
DSA Javascript
let val1 = l1 ? [1] : 0; let val2 = l2 ? [2] : 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using .next instead of .val returns the next node, not the value.
Not checking for null nodes causes runtime errors.
✗ Incorrect
We get the value from l1.val and l2.val if nodes exist, else 0.
5fill in blank
hardFill all three blanks to move to the next nodes or null safely.
DSA Javascript
l1 = l1 ? [1] : null; l2 = l2 ? [2] : null; current = current.[3];
Attempts:
3 left
💡 Hint
Common Mistakes
Using .val instead of .next moves to value, not node.
Using .prev is wrong because list is singly linked.
✗ Incorrect
We move l1 and l2 to their next nodes, and current to current.next to build the list.
