# Linked List Cycle — coding interview question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3214/linked-list-cycle
Source observed: 2026-11-04T23:34:50.727Z
Last checked: 2026-11-04T23:34:50.727+00:00
Indexed: 2026-11-05T13:21:34.578+00:00

---

# Linked List Cycle

**Difficulty:** Easy  
**Category:** Data Structures & Algorithms  
**Reported interviews:** 9  
**Last asked:** 5 days ago (as displayed on the page)  
**Community:** 24  
**Save count:** 35

We provide this coding interview practice question through Aced, formerly Exponent. It asks you to determine whether a singly linked list contains a cycle.

## Problem

Given the head of a linked list, write a function `hasCycle` to determine if the linked list has a cycle in it. A linked list has a cycle when a node’s `next` pointer points to a previous node in the list, forming a loop. Return `true` when a cycle exists; otherwise, return `false`.

## Example

![Linked List Cycle example: the left list cycles from node 5 back to node 1, while the right list terminates after node 5.](https://images.ctfassets.net/x78yjrjc11pq/2YYJb0gJ9rdKz8rQ9bb0tD/23868b51bf812a5a6946e51474d70742/Max__Linked_List_Cycle.png)

The diagram shows two cases:

- **Has cycle:** `1 → 2 → 3 → 4 → 5 → 1`, because node 5 points back to node 1.
- **No cycle:** `1 → 2 → 3 → 4 → 5`, with no pointer returning to an earlier node.

The page includes two additional expandable practice sections labeled **Challenge 1** and **Challenge 2**. The solution tab is available, but no solution content was supplied in the captured page. The community section has no contributed answers in the supplied text.

## Interview experiences

We show three shared interview experiences associated with this question:

- [Amazon interview experience](https://www.aced.io/experiences/amazon-software-engineer-interview-5766eb) — **Software Engineer, Entry Level / L3**, shared 5 days ago: “The process seems to be getting more rigorous than the past, with multiple technical rounds. There is a large focus on the leadership principles.”
- [Cognizant interview experience](https://www.aced.io/experiences/cognizant-software-engineer-interview-fb7044) — **Software Engineer, Entry Level / L3**, shared a year ago: “The Process was easy, even though I am in my final year of B.Tech. I would say basics from multiple domains or tech stacks are enough to get into Cognizant for freshers.”
- [Meta interview experience](https://www.aced.io/experiences/meta-facebook-senior-software-engineer-interview-999e45) — **Software Engineer, Senior / L5**, shared 2 years ago: “It mostly went well. I was thrown off by the fact that a lot of the focus in the system design rounds was on the product and UX side, only to discover it was product architecture later and that there had been a miscommunication.”

## Related questions

- [Reorder linked list.](https://www.aced.io/questions/5703/reorder-linked-list)
- [Reverse a linked list.](https://www.aced.io/questions/3247/reverse-linked-list)
- [Merge two sorted linked list](https://www.aced.io/questions/5566/merge-two-sorted-linked-list)

## Related courses

### [Machine Learning Engineer Interview Prep](https://www.aced.io/courses/ml-engineer)

![Machine Learning Engineer Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/6UfkHxUyLQVfDHSfLNQtWa/1be1539a65b4f6f15201f5b573c0a578/ML_Engineer_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We cover mock interviews, frameworks, and advice from senior candidates for machine-learning roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies. Topics include ML system design, core concepts, coding, and behavioral interviews.

### [Data Science Interview Prep](https://www.aced.io/courses/data-science)

![Data Science Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/3U4C5C0OkDR0UeGch4AmlE/7ad489430b676a088cb973307fe77884/Data_Science_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We cover statistics, experimentation, coding, SQL, machine learning, and behavioral interviews for data-science roles at Google, Amazon, Microsoft, Meta, Apple, and other top companies, using mock interviews, frameworks, and advice from senior candidates.

## Running code

The page includes a Python editor with **Editor**, **Share**, **Output**, **Test Results**, and **Console** panels. The captured editor was still loading and did not expose starter code, a solution, or test cases. [Sign up to run code](https://www.aced.io/signup?src=lesson).

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3214%2Flinked-list-cycle&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3214%2Flinked-list-cycle). Opening a form does not execute a tool.