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
Coding & Algorithms
Software Engineer
Flipkart
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

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
bit manipulation
XOR
constant space
math
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported