Code Room
CodingMediumcod-g344
Subject Linked listsLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A singly linked list is encoded as next_arr, where next_arr[i] is the index of the node that follows node i, or -1 if it is the tail. head is the starting node index (or -1 for an empty list). If the list contains a cycle, return the index of the node where the cycle begins; otherwise return -1. Solve in O(1) extra space.

Implement
cycle_entry(next_arr: list[int], head: int) → int
Examples
in[[1,2,3,1],0]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.