448. Find All Numbers Disappeared in an Array LeetCode Solution
In this guide, you will get 448. Find All Numbers Disappeared in an Array LeetCode Solution with the best time and space complexity. The solution to Find All Numbers Disappeared in an Array problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Find All Numbers Disappeared in an Array solution in C++
- Find All Numbers Disappeared in an Array solution in Java
- Find All Numbers Disappeared in an Array solution in Python
- Additional Resources

Problem Statement of Find All Numbers Disappeared in an Array
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 do not appear in nums.
Example 1:
Input: nums = [4,3,2,7,8,2,3,1]
Output: [5,6]
Example 2:
Input: nums = [1,1]
Output: [2]
Constraints:
n == nums.length
1 <= n <= 105
1 <= nums[i] <= n
Follow up: Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.
Complexity Analysis
- Time Complexity: O(n)
- Space Complexity: O(1)
448. Find All Numbers Disappeared in an Array LeetCode Solution in C++
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
vector<int> ans;
for (const int num : nums) {
const int index = abs(num) - 1;
nums[index] = -abs(nums[index]);
}
for (int i = 0; i < nums.size(); ++i)
if (nums[i] > 0)
ans.push_back(i + 1);
return ans;
}
};
/* code provided by PROGIEZ */
448. Find All Numbers Disappeared in an Array LeetCode Solution in Java
class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> ans = new ArrayList<>();
for (final int num : nums) {
final int index = Math.abs(num) - 1;
nums[index] = -Math.abs(nums[index]);
}
for (int i = 0; i < nums.length; ++i)
if (nums[i] > 0)
ans.add(i + 1);
return ans;
}
}
// code provided by PROGIEZ
448. Find All Numbers Disappeared in an Array LeetCode Solution in Python
class Solution:
def findDisappearedNumbers(self, nums: list[int]) -> list[int]:
for num in nums:
index = abs(num) - 1
nums[index] = -abs(nums[index])
return [i + 1 for i, num in enumerate(nums) if num > 0]
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.