Lesson overview · Free interview practice

Fast and Slow Pointers

Detect cycles in linked lists and solve related problems.

Topics in the full lesson
  • Concept and Use Cases
  • When to Use
  • Time and Space Complexity
  • Cycle Detection in a Linked List
  • Finding the Start of a Cycle in a Linked List
  • Finding the Middle of a Linked List

Practice Problems

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

Completion marks record your own progress, not an automatically checked result. The task type does not determine whether it is optional.

CodingEasy

Happy Number

Question

Determine if a given number is a "happy number," defined as a number where the sum of the squares of its digits eventually reaches 1, or remains at 1 in a loop, without descending to a negative value.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Given the head of a linked list, return the node where a cycle begins if there is a cycle, otherwise return null. Floyd's tortoise-and-hare algorithm finds the cycle and then the entry point in O(n) time with O(1) extra space.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Given an array nums containing n + 1 integers where each integer is in the inclusive range [1, n], there is exactly one duplicated value. Return the duplicated value without modifying nums and using only constant extra space.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Fast and Slow Pointers material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium