As reported: Cisco online assessment on HackerRank (2025), problem 1 "Filtration": a singly linked list contains a loop (the last node points to one of the nodes); return a pointer to the node where the loop starts. Example:
arr = [1,2,3,4,5], the last node points to index 2, so the loop starts at the node with value 3. Constraints:1 ≤ n ≤ 100; node values in0..10000; values may repeat.
Given the head of a linked list, return the node where the cycle begins, or null if there is no cycle. The cycle is described in the input by pos, the index the tail links back to (-1 for no cycle); your function receives only the head. Do not modify the list.
This is LeetCode 142 — Linked List Cycle II.
Example 1
head = [1,2,3,4,5], pos = 2 -> the node at index 2 (value 3)
Example 2
head = [3,2,0,-4], pos = 1 -> the node at index 1
Example 3
head = [1], pos = -1 -> null
Constraints: 0 ≤ n ≤ 10^4; -10^5 ≤ Node.val ≤ 10^5; pos is -1 or a valid index.
Code runner format: one JSON value per line: the list values, then pos. Implement detectCycle(head); the harness prints which index the returned node is ("tail connects to node index 2") or "no cycle". Values may repeat, so return the node itself, not its value.