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 'node' or 'next' instead of the value.
Using 'head' which is a node, not a value.
✗ Incorrect
The constructor of ListNode takes the value 'val' to create a new node.
2fill in blank
mediumComplete the code to move the pointer to the next node in the list.
DSA C#
current = current[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which points backward.
Using 'val' which is the node's value, not a pointer.
✗ Incorrect
To move forward in a linked list, we assign current to current.next.
3fill in blank
hardFix the error in the if condition to compare node values correctly.
DSA C#
if (list1[1].val <= list2.val) {
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing list1 directly without accessing its next node.
Using 'prev' or 'head' which are not valid here.
✗ Incorrect
We must check the value of the next node in list1 to compare with list2's current value.
4fill in blank
hardFill both blanks to correctly attach the smaller node and move the pointer.
DSA C#
current.next = [1]; current = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Attaching list2 when list1 is smaller.
Moving current to 'current' instead of 'current.next'.
✗ Incorrect
We attach list1 to current.next and then move current to current.next to continue.
5fill in blank
hardFill all three blanks to return the merged list starting after the dummy node.
DSA C#
return [1].[2]; // Also, update pointers: list1 = list1.[3];
Attempts:
3 left
💡 Hint
Common Mistakes
Returning dummy instead of dummy.next.
Using 'prev' instead of 'next' to move pointers.
✗ Incorrect
Return dummy.next as the head of merged list and move list1 to list1.next.
