Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the middle node of the linked list using slow and fast pointers.
DSA Javascript
let slow = head; let fast = head; while (fast && fast.next) { slow = slow.[1]; fast = fast.next.next; } return slow;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' causes the pointer to move backward.
Using 'val' or 'data' accesses the node value instead of the next pointer.
✗ Incorrect
To move the slow pointer one step forward, move to slow.next.
2fill in blank
mediumComplete the code to reverse the second half of the linked list starting from the middle node.
DSA Javascript
let prev = null; let curr = middle; while (curr) { let nextTemp = curr.next; curr.next = [1]; prev = curr; curr = nextTemp; } return prev;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting curr.next to curr or nextTemp breaks the reversal.
Using middle instead of prev causes incorrect links.
✗ Incorrect
To reverse the list, each node's next pointer should point to the previous node.
3fill in blank
hardFix the error in the code that merges two halves of the linked list alternately.
DSA Javascript
let first = head; let second = reversed; while (second) { let temp1 = first.next; let temp2 = second.next; first.next = second; second.next = [1]; first = temp1; second = temp2; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using temp2 or second causes cycles or wrong links.
Using first instead of temp1 breaks the chain.
✗ Incorrect
After linking second node, its next should point to the next node of first half (temp1).
4fill in blank
hardFill both blanks to split the linked list into two halves by breaking the link at the middle.
DSA Javascript
let slow = head; let fast = head; while (fast && fast.next) { slow = slow.next; fast = fast.next.next; } let secondHalf = slow.next; slow.[1] = null; return [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Setting slow.prev instead of slow.next causes errors.
Returning head instead of secondHalf returns the first half.
✗ Incorrect
Setting slow.next to null breaks the list into two halves. We return the second half starting at secondHalf.
5fill in blank
hardFill all three blanks to reorder the linked list by merging first and reversed second halves alternately.
DSA Javascript
let first = head; let second = reversed; while (second) { let temp1 = first.next; let temp2 = second.next; first.next = [1]; second.next = [2]; first = [3]; second = temp2; }
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping temp1 and second causes wrong links.
Moving first to first instead of temp1 causes infinite loop.
✗ Incorrect
Link first.next to second, second.next to temp1, then move first to temp1 to continue merging.
