Single Number II
Problem Statement
You get an array nums. Every value in it appears three times, except for one value that appears exactly once. Return that single value.
Your solution must run in linear time and use constant extra space.
An integer array nums with at least one value. Every value appears three times except one, which appears once.
The one value that appears exactly once.
2 shows up three times. The 3 is the one that shows up once.
0 and 1 each show up three times. The 99 is the single one.
- • 1 ≤ nums.length ≤ 3 · 10^4
- • −2^31 ≤ nums[i] ≤ 2^31 − 1
- • Every value appears exactly three times, except one value that appears 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 return the one that appears exactly once
Count each value once in a hash map, then return the value with count 1
For each of the 32 bit positions, count the 1s; set the answer's bit when the count % 3 is 1
For each value in nums, scan the whole array and count how many times it appears. The first value whose count is 1 is the answer.
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.