Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Middle of Linked List Lab
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
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 1.0x