Find All Numbers Disappeared in an Array
Problem Statement
You are given an array nums of n integers, where every value is between 1 and n. Some values appear more than once, so some other values in 1..n do not appear at all.
Return all the values in 1..n that are missing from nums, in any order.
Follow-up: can you do it in O(N) time with no extra space? The returned list does not count as extra space.
An integer array nums of length n with values in 1..n (duplicates allowed).
A list of every value in 1..n that does not appear in nums.
n = 8. The values 2 and 3 appear twice, which uses up the two places that 5 and 6 would have needed.
n = 2. Only 1 appears, so 2 is missing.
- • n == nums.length
- • 1 ≤ n ≤ 10^5
- • 1 ≤ nums[i] ≤ n
- • Follow-up: O(N) time, O(1) extra space (output not counted).
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
For each k in 1..n, scan the array; collect the ones not found
Mark each value in a boolean array, then collect the unmarked ones
Swap each value v into index v − 1 until its home holds v, then every wrong slot i gives i + 1
For each k = 1, 2, …, n, scan the whole array. If k is never found, add it to 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 Cyclic Sort 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.