Code RoomLinked list cycle start
MediumPrep Room Coding #914

Linked list cycle start

CodingAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
[[1,2,3,1],0]1not run yetsample