Find the Duplicated Request ID Using Constant Extra Memory
Last updated: November 29, 2026
Quick Overview
An array of n + 1 request IDs contains only values from 1 to n, so at least one ID repeats. Return a repeated ID without modifying the array and using O(1) extra space.
0
0
0 solved
An array of n + 1 request IDs contains only values from 1 to n, so at least one ID repeats. Return a repeated ID without modifying the array and using O(1) extra space.
A Google onsite question that starts easy (a hash set) and then tightens constraints to force Floyd's cycle detection on the implicit linked list i -> nums[i]. The interviewer probes whether you can explain why a cycle exists and why its entrance is the duplicate.
What the Interviewer Expects
- Gives the hash set solution and its O(n) space cost
- Models the array as a functional graph i -> nums[i]
- Applies Floyd's tortoise and hare to find the cycle entrance
- Explains why the entrance is the duplicated value
- Mentions the binary search on value range as an O(n log n) alternative
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Prove that the meeting-point reset finds the cycle entrance.
- Solve it with binary search on the value range and count elements; what is the complexity?
- What if multiple values repeat; which one does Floyd's return?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list
idsof length n + 1 with every value in [1, n]. - Output: any value that appears at least twice.
- Constraints: do not modify
ids, O(1) extra space, better than O(n^2) time....
High-Level Design
Treat each index as a node with an edge to ids[i]. Since values are in [1, n], index 0 has no incoming edge from itself as a value, so starting at 0 we walk a path that must eventually enter a cycle...