Identify Two Return Labels Missing Their Matching Scan

Last updated: November 29, 2026

Quick Overview

In a returns log every return label ID appears exactly twice (printed and scanned) except two IDs that each appear once. Return those two IDs in ascending order using linear time and constant extra space.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


In a returns log every return label ID appears exactly twice (printed and scanned) except two IDs that each appear once. Return those two IDs in ascending order using linear time and constant extra space.

A natural follow-up in Amazon technical screens after the single-unmatched-ID warm-up. The interviewer checks whether you can split the problem with the lowest differing bit instead of falling back to a hash map.

What the Interviewer Expects
  • XORs everything to get a ^ b
  • Isolates a set bit of a ^ b with x & -x
  • Partitions IDs by that bit and XORs each group
  • Argues why a and b land in different groups
  • Returns sorted output and handles negatives
Key Topics to Cover
XOR
lowest set bit
partitioning
two's complement
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 the two unmatched IDs could be equal?
  • Generalize to k unmatched IDs: what is the best you can do?
  • How would you do this when the log is split across three machines?
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: a list of integers with exactly two values appearing once and the rest appearing twice. The two values are distinct. Output: the two values sorted ascending. O(n) time, O(1) extra space....

High-Level Design

XOR of the whole list is x = a ^ b, nonzero because a and b differ. Any set bit of x marks a position where a and b disagree. Take the lowest one with x & -x. Split all IDs into those with that bi...


Submit Your Answer
Markdown supported