Detect shuffle-mode sequence
Company: Roblox
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates algorithm design and analysis skills, focusing on reasoning about permutations, sequence consistency under different randomness models, and handling repeated elements within observed streams in the Coding & Algorithms domain.
Constraints
- 1 <= len(playlist) = m <= 200000
- 1 <= len(observed) = n <= 200000
- playlist contains distinct integers
- All observed songs must be in playlist for the answer to be true
- Song IDs fit in 32-bit signed integers
Hints
- Any valid segmentation corresponds to choosing a single offset t in [0, m] and then cutting every m songs thereafter.
- For any song that repeats at positions i < j with j - i < m, there must be a cut between i and j; this forces t modulo m to lie in a specific circular interval.
- Intersect all such circular intervals (for adjacent occurrences) to find if any t modulo m satisfies them all. Use a difference array on residues 0..m-1 for O(n + m) time.