Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Javascript
function ListNode(val) {
this.val = val;
this.next = [1];
}Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined or 0 instead of null for the next pointer.
✗ Incorrect
The next pointer of a new node should be null to indicate the end of the list.
2fill in blank
mediumComplete the code to start merging by creating a dummy node.
DSA Javascript
let dummy = new ListNode([1]);
let current = dummy;Attempts:
3 left
💡 Hint
Common Mistakes
Using null or undefined as node value causes errors.
✗ Incorrect
Using -1 as dummy node value is common to avoid confusion with list values.
3fill in blank
hardFix the error in the condition to compare node values correctly.
DSA Javascript
while (list1 !== null && list2 !== null) { if (list1.val [1] list2.val) { current.next = list1; list1 = list1.next; } else { current.next = list2; list2 = list2.next; } current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' picks larger values first, breaking sorted order.
✗ Incorrect
We pick the smaller value node first, so use less than operator.
4fill in blank
hardFill both blanks to attach the remaining nodes after the loop.
DSA Javascript
if (list1 !== null) { current.next = [1]; } else { current.next = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Attaching dummy or current instead of the remaining list.
✗ Incorrect
Attach whichever list still has nodes left to the merged list.
5fill in blank
hardFill both blanks to return the merged list skipping the dummy node.
DSA Javascript
return [1].[2];
Attempts:
3 left
💡 Hint
Common Mistakes
Returning dummy or current directly instead of dummy.next.
✗ Incorrect
Return dummy.next to skip the dummy node and get the merged list head.
