Floyd's algorithm, two pointers, slow and fast.
Start by clarifying the problem constraints (e.g., can the list be modified, are there memory limits) and then present Floyd's cycle-finding algorithm (tortoise and hare) as the optimal solution. Explain the algorithm step-by-step, analyze its time and space complexity, and discuss edge cases and alternatives.
Pro tip: Mention that Floyd's algorithm is preferred because it uses O(1) space and is optimal for Apple's focus on efficiency; also note that you can find the start of the cycle after detection, which often impresses interviewers.
Ask if the linked list can be modified, if extra space is allowed, and what the expected time/space complexity is. This shows you consider practical constraints.
Suggest Floyd's cycle-finding algorithm: use two pointers, slow moves one step, fast moves two steps. If they meet, there's a cycle.
Detail how the pointers move and why they must meet if a cycle exists. Mention that if fast reaches null, there's no cycle.
State that time complexity is O(n) and space complexity is O(1). Compare with alternatives like hash set (O(n) space).
Cover empty list, single node, cycle at head, and how to find the cycle's start (reset slow to head and move both one step).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.