Find All Numbers Disappeared in Array Problem
Find All Numbers Disappeared in Array Problem — ExecCode School DSA Practice
Solve the Find All Numbers Disappeared in Array problem on ExecCode. Free online school DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an array nums of n integers where every value is in the range [1, n], return an array of all the integers in [1, n] that do not appear in nums. Solve it in O(n) time using only the input array for extra space, via cyclic sort placement.
Examples
Input nums = [4, 3, 2, 7, 8, 2, 3, 1]; Output [5, 6]. Input nums = [1, 1]; Output [2]. Input nums = [1, 2, 3, 4]; Output []
Constraints
n == nums.length 1 <= n <= 10^5 1 <= nums[i] <= n
Practice Find All Numbers Disappeared in Array free on ExecCode. Browse DSA problems, topic map, and placement guides.