Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Java
ListNode newNode = new ListNode([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that are not defined like 'value' or 'node'.
Confusing the head node with the 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 Java
current = current.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which points backward.
Using undefined pointers like 'child' or 'head'.
✗ Incorrect
To move forward in a linked list, we use the 'next' pointer.
3fill in blank
hardFix the error in the condition to check if the first list is empty.
DSA Java
if (list1 [1] null) { return list2; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which assigns instead of compares.
Using '!=' which checks for not null.
✗ Incorrect
To check equality in Java, use '==', not '=' which is assignment.
4fill in blank
hardFill both blanks to correctly compare node values and assign the next pointer.
DSA Java
if (list1.val [1] list2.val) { merged.next = list1; list1 = list1.[2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which reverses the order.
Using 'prev' which points backward.
✗ Incorrect
We compare if list1's value is less than list2's, then move list1 to its next node.
5fill in blank
hardFill all three blanks to complete the while loop that merges two sorted lists.
DSA Java
while (list1 != null && list2 != null) { if (list1.val [1] list2.val) { merged.next = list1; list1 = list1.[2]; } else { merged.next = list2; list2 = list2.[3]; } merged = merged.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' which reverses the logic.
Using 'prev' which moves backward.
✗ Incorrect
We use '<=' to compare values, and 'next' to move pointers forward in both lists.
