Find All Numbers Disappeared in an Array gives an array whose values range from one to its length. Return every number in that range that is missing from the array, even when values repeat.
Statement
Given an array, nums, of n integers where nums[i] is in the range [1,n], return an array of all the integers in the range [1,n] that doesn’t appear in nums.
Constraints:
n=nums.length
1≤n≤103
1≤nums[i]≤n
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Find All Numbers Disappeared in an Array
1.
What is the output if the following array is given as input?
nums = [1, 2, 7, 3, 8, 3, 4]
A.
[5, 6]
B.
[0, 5, 6]
C.
[1, 2, 3, 3, 4, 5, 6, 7, 8]
1 / 2
Try it yourself
Implement your solution in the following coding playground:
The optimal solution to this problem runs in O(n) time and takes O(1) space.
Find All Numbers Disappeared in an Array gives an array whose values range from one to its length. Return every number in that range that is missing from the array, even when values repeat.
Statement
Given an array, nums, of n integers where nums[i] is in the range [1,n], return an array of all the integers in the range [1,n] that doesn’t appear in nums.
Constraints:
n=nums.length
1≤n≤103
1≤nums[i]≤n
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Find All Numbers Disappeared in an Array
1.
What is the output if the following array is given as input?
nums = [1, 2, 7, 3, 8, 3, 4]
A.
[5, 6]
B.
[0, 5, 6]
C.
[1, 2, 3, 3, 4, 5, 6, 7, 8]
1 / 2
Try it yourself
Implement your solution in the following coding playground:
The optimal solution to this problem runs in O(n) time and takes O(1) space.