Find the One Return Shipment Scanned Only Once
Last updated: November 29, 2026
Quick Overview
At a returns hub, every parcel ID is scanned twice (inbound and outbound) except one parcel that was scanned only once. Given the list of scanned integer IDs, find that parcel in O(n) time and O(1) extra space.
Flipkart
November 29, 20260
0
0 solved
At a returns hub, every parcel ID is scanned twice (inbound and outbound) except one parcel that was scanned only once. Given the list of scanned integer IDs, find that parcel in O(n) time and O(1) extra space.
A short bit manipulation item in Flipkart online assessments, framed around reverse logistics at returns processing centers. The grader is checking whether you know the XOR cancellation trick and can justify it, rather than reaching for a hash set.
What the Interviewer Expects
- Give the hash set solution first and note its O(n) space
- Use XOR: x ^ x = 0 and x ^ 0 = x, and XOR is order independent
- Prove that paired IDs cancel out
- State O(n) time, O(1) space
- Discuss what breaks if two parcels are unpaired
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 exactly two parcels were scanned once?
- What if every other parcel is scanned three times instead of twice?
- What if the IDs are strings like 'FMPC123' instead of integers?
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 of non negative integer parcel IDs, length
2m + 1. - Every ID appears exactly twice except one, which appears once.
- Output: that ID, with O(1) extra memory....
High-Level Design
A set that adds on first sight and removes on second sight works but uses O(n) memory. XOR has three useful properties: x ^ x = 0, x ^ 0 = x, and it is commutative and associative. XOR all IDs tog...