Dashboard
LC #448

Find All Numbers Disappeared in an Array

Pattern · ?AmazonGoogle

Problem

Given an array nums of n integers where each element is in the range [1, n], some elements appear twice and some appear once. Find all the integers in [1, n] that do not appear in nums.

Constraints

  • n == nums.length
  • 1 ≤ n ≤ 10⁵
  • 1 ≤ nums[i] ≤ n
  • O(1) extra space (excluding output)

Example

Input
nums = [4, 3, 2, 7, 8, 2, 3, 1]
Output
[5, 6]
Why
n=8, range [1,8]. Numbers 5 and 6 do not appear

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗