Skip to content
Learn Netverks
Company prep Datadog
Fresher (0–1 years) Coding / DSA Easy

Detect cycle in linked list using Floyd algorithm

Reported in Datadog interview loops. Classic linked list pointer question in entry and mid-level interviews.

Role
SDE
Location
Chennai

Context for Datadog candidates:

Given the head of a linked list, determine whether it contains a cycle.

Try answering aloud first

Cover trade-offs, structure, and a concrete example before revealing the baseline response.

Spoiler-free prep mode

How to frame this at Datadog: Connect your answer to measurable impact, clarity of thought, and trade-offs the team cares about. Below is a strong baseline response you can adapt with your own project examples.

Use two pointers: slow moves one step, fast moves two steps. If there is a cycle, fast eventually laps slow and both pointers meet; if fast reaches null, there is no cycle.

This approach avoids additional hash memory and runs in O(n) time and O(1) space. Interviewers also like a follow-up: after meeting, reset one pointer to head and move both one step to find the cycle start.

Comments (0)

Share how this question came up in your loop, or add tips for others preparing.

Log in to comment on this question.