Find Where a Corrupted Up Next Queue Loops Back on Itself

Last updated: November 29, 2026

Quick Overview

The Up Next queue is a singly linked list of tracks. A sync bug may cause the last node to point back to an earlier node, forming a loop. Return the node where the loop starts, or None if the queue is acyclic, using O(1) extra memory.

Apple
Coding & Algorithms
Software Engineer
Apple
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


The Up Next queue is a singly linked list of tracks. A sync bug may cause the last node to point back to an earlier node, forming a loop. Return the node where the loop starts, or None if the queue is acyclic, using O(1) extra memory.

Linked structures still show up in Apple's media and system code, and corrupted pointers are a real debugging scenario. The interviewer checks Floyd's tortoise and hare, and especially whether you can explain why resetting one pointer to the head finds the loop entry.

What the Interviewer Expects
  • Give the hash set baseline with O(n) memory
  • Detect the loop with slow and fast pointers
  • Find the entry by restarting one pointer from the head
  • Prove why both pointers meet at the entry
  • Handle empty and single-node lists
Key Topics to Cover
linked lists
Floyd cycle detection
two pointers
constant space
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the loop length too.
  • Repair the queue by breaking the loop.
  • Detect corruption in a doubly linked list where prev pointers may disagree with next pointers.
  • How would you prevent this class of bug in the sync code?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: head of a list of Track(title, next). Output: the first node of the loop, or None. The list must not be modified. Use O(1) extra space....

High-Level Design

Move slow one step and fast two steps. If they ever meet, there is a loop; if fast reaches the end, there is none. Let a be the distance from head to the loop entry, b the distance from the entr...


Submit Your Answer
Markdown supported