Linked list cycle start
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) → intExamples
in
[[1,2,3,1],0]out1What 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
solution.py
InputExpectedGot
[[1,2,3,1],0]1not run yetsample