All lessons

3. Linked Lists

Classic list algorithms

0 of 5 activities0%

Reading 1

Patterns you will reuse

Open

Reverse: iterate with prev, cur, nextptr rewiring.

Middle: slow moves one step, fast moves two; when fast ends, slow is mid.

Cycle detection (Floyd): slow and fast; if they meet, there is a cycle.

These show up constantly in interviews.

Node* slow=head, *fast=head;
while (fast && fast->next) {
  slow=slow->next;
  fast=fast->next->next;
}

Check 2

Middle trick

Open

Slow/fast pointers find the middle because

Fill in 3

Cycle name

Open

Floyd’s cycle-finding algorithm is also called the

Try it 4

Reverse iterative

Open

Reverse 1-2-3.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Print reversed values

Open

Read n and n ints into an array (simulating a list). Print them in reverse order separated by spaces.

main.cpp
Loading editor…