Recover Two Singly Occurring Signed Values

Quick Overview

Recover Two Singly Occurring Signed Values. Exactly two values in nums occur once; every other value occurs twice. Return the two single-occurrence values in either order, using linear time and constant e

Recover Two Singly Occurring Signed Values

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Exactly two values in nums occur once; every other value occurs twice. Return the two single-occurrence values in either order, using linear time and constant extra space. ```cpp vector<int> singleNumber(vector<int>& nums); ``` ### Examples ```text nums = [4,1,4,2,1,9] -> [2,9] nums = [-2147483648,0] -> [-2147483648,0] ``` ### Constraints - Length is 2 through 30000. - Values span the full signed 32-bit domain. - Precisely two distinct values occur once and every other value twice. ### Follow-up Questions Explain how the permitted output freedom is preserved without losing required values or occurrences. ### What a Strong Answer Covers XOR all 32-bit patterns, then partition by one set bit of that XOR and XOR within each partition. Explain why every produced result satisfies the source contract and why no required result is omitted.

Overview: Recover Two Singly Occurring Signed Values. Exactly two values in nums occur once; every other value occurs twice. Return the two single-occurrence values in either order, using linear time and constant e

Amazon logo
Amazon
Jul 17, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Exactly two values in nums occur once; every other value occurs twice. Return the two single-occurrence values in either order, using linear time and constant extra space.

vector<int> singleNumber(vector<int>& nums);

Examples

nums = [4,1,4,2,1,9] -> [2,9]
nums = [-2147483648,0] -> [-2147483648,0]

Constraints

  • Length is 2 through 30000.
  • Values span the full signed 32-bit domain.
  • Precisely two distinct values occur once and every other value twice.

Follow-up Questions Guidance

Explain how the permitted output freedom is preserved without losing required values or occurrences.

What a Strong Answer Covers Guidance

XOR all 32-bit patterns, then partition by one set bit of that XOR and XOR within each partition. Explain why every produced result satisfies the source contract and why no required result is omitted.