Linked Lists

Problem shape

Beginner
7
->
11
->
18
->
24
Core idea

Move a slow pointer one step and a fast pointer two steps.

Step 1 / 5
Problem shape
Current lesson

Middle of Linked List Lab

Linked Lists Beginner

Middle of Linked List

Welcome to the Middle of Linked List algorithm lab. Move a slow pointer one step and a fast pointer two steps. Use it when: Use for midpoint, cycle, and fast-slow pointer practice. The time complexity is O(n), and the space complexity is O(1). The pseudocode is: slow = head, fast = head while fast and fast.next slow = slow.next fast = fast.next.next return slow As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(n)

Space

O(1)

Pseudocode

slow = head, fast = head
while fast and fast.next
  slow = slow.next
  fast = fast.next.next
return slow
Open deeper structure lesson
1.0x