Complete the code to initialize the slow pointer at the head of the linked list.
let slow = [1];The slow pointer should start at the head of the linked list to begin traversal.
Complete the code to move the fast pointer two steps ahead in the linked list.
fast = fast[1]next[2]next;
Using optional chaining (?.) safely moves the fast pointer two steps ahead without errors if next is null.
Fix the error in the while loop condition to check if fast and fast.next exist.
while (fast [1] null && fast.next [2] null) {
The condition should check that fast and fast.next are not null to continue the loop.
Fill both blanks to move slow one step and fast two steps safely.
slow = slow[1]next; fast = fast[2]next[3]next;
Slow moves one step with dot operator, fast moves two steps with optional chaining to avoid errors.
Fill all three blanks to return the value of the middle node after traversal.
function findMiddle(head: ListNode | null): number | null {
let slow = head;
let fast = head;
while (fast [1] null && fast.next [2] null) {
slow = slow[3]next;
fast = fast.next.next;
}
return slow ? slow.val : null;
}The while loop checks that fast and fast.next are not null using !==, and slow moves one step safely with dot operator.
