Find the One Package Scanned Only Once at a Sort Center
Last updated: November 29, 2026
Quick Overview
Every package passing through a sort center is scanned exactly twice (inbound and outbound) except one package that was scanned only once. Given the list of scanned package IDs as integers, return the ID of that package using O(1) extra space.
Amazon
November 29, 20260
0
0 solved
Every package passing through a sort center is scanned exactly twice (inbound and outbound) except one package that was scanned only once. Given the list of scanned package IDs as integers, return the ID of that package using O(1) extra space.
A typical Amazon phone screen warm-up dressed in fulfillment language. The interviewer wants to see whether you go past the hash-set answer to the XOR trick and can explain why it works, then talk through the O(1) space constraint as a real concern for a streaming scanner.
What the Interviewer Expects
- States the hash-set solution first and its O(n) space cost
- Uses XOR and explains a ^ a = 0 and a ^ 0 = a
- Handles negative IDs and a single-element list
- Gives O(n) time, O(1) space
- Writes clean code with no special cases
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
- What if every other package was scanned three times instead of twice?
- What if two packages were scanned once each?
- How would you do this over a stream split across many sort centers?
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: a non-empty list of integers where every value appears exactly twice except one value that appears once. Output: that single value. Constraints: linear time and constant extra memory, because i...
High-Level Design
A set (add on first sight, remove on second) works but costs O(n) memory. XOR is better: it is associative and commutative, x ^ x = 0, and x ^ 0 = x. If we XOR every ID together, each paired ID ca...