Understand how to find all missing integers in an array of size n with values in the range 1 to n. Learn to implement an efficient solution with linear time complexity and constant additional space, enhancing your problem-solving skills for coding interviews.
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.
Understand how to find all missing integers in an array of size n with values in the range 1 to n. Learn to implement an efficient solution with linear time complexity and constant additional space, enhancing your problem-solving skills for coding interviews.
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.