Single Number III
Problem Statement
You get an array nums. Every value in it appears twice, except for two values that each appear only once. Return those two values, in any order.
Your solution must run in linear time and use constant extra space.
An integer array nums with at least two values. Exactly two values appear once, and every other value appears twice.
The two values that appear exactly once, in any order.
1 and 2 each appear twice. 3 and 5 appear once, so they are the answer. [5, 3] is also accepted.
Both values appear once. Negative numbers are allowed.
The same two values in the other order, which is also correct.
- • 2 ≤ nums.length ≤ 3 · 10^4
- • −2^31 ≤ nums[i] ≤ 2^31 − 1
- • Every value appears twice, except exactly two values that appear once.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
For each value, scan the array and keep it when its count is 1
Count every value once in a hash map, then return the values with count 1
XOR everything to get a ^ b, pick one set bit, and XOR each group split by that bit
For each value in nums, scan the whole array and count how many times it appears. Keep every value whose count is exactly 1. Those are the two answers.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Bit Manipulation translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.