Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a program to detect a cycle in a linked list.

Hard

Problem Statement

Write a program to detect a cycle in a linked list.

Sample Input

Linked List: 1 -> 2 -> 3 -> 4 -> 2 (cycle)

Sample Output

Cycle detected: true

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
class ListNode { val: number; next: ListNode
Log in or sign up to run or submit your code.Log inSign up
Input
Linked List: 1 -> 2 -> 3 -> 4 -> 2 (cycle)
Expected Output
Cycle detected: true