Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the sum digit.
DSA Typescript
let newNode = new ListNode([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using sum + 10 instead of modulo.
Using division instead of modulo.
Multiplying sum by 10.
✗ Incorrect
We create a new node with the digit value which is sum modulo 10.
2fill in blank
mediumComplete the code to update the carry for the next addition.
DSA Typescript
carry = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using modulo instead of division for carry.
Adding carry to sum again.
Multiplying sum by 10.
✗ Incorrect
Carry is the tens digit of sum, so we use floor division by 10.
3fill in blank
hardFix the error in the loop condition to continue while nodes or carry exist.
DSA Typescript
while (l1 !== null || [1] !== null || carry !== 0) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking carry twice instead of l2.
Checking l1 twice.
Checking sum which is not a node.
✗ Incorrect
We must check if l2 is not null to continue adding nodes.
4fill in blank
hardFill both blanks to safely get values from nodes or zero if null.
DSA Typescript
const val1 = l1 ? [1] : 0; const val2 = l2 ? [2] : 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using .next instead of .val.
Not checking for null before accessing value.
✗ Incorrect
We get the value from each node if it exists, else zero.
5fill in blank
hardFill all three blanks to move to the next nodes or null.
DSA Typescript
l1 = l1 ? [1] : null; l2 = l2 ? [2] : null; current = current.[3];
Attempts:
3 left
💡 Hint
Common Mistakes
Using .val instead of .next to move nodes.
Using .prev which does not exist in singly linked list.
✗ Incorrect
Move l1 and l2 to their next nodes, and current to its next node.
