217. Find All Numbers Disappeared in an Array
Easy
Index Marking
Array
Problem
Given an integer array nums of length n where every value is between 1 and n, return all numbers in the range [1, n] that do not appear in nums.
Examples
Example 1
Input: [4,3,2,7,8,2,3,1]
Output: [5,6]
Example 2
Input: [1,1]
Output: [2]
Example 3
Input: [1,2,3]
Output: []
Constraints
� 1 <= nums.length <= 100000
� 1 <= nums[i] <= nums.length
Hints
?? Use each value as an index.
?? Mark visited indices using sign changes or cyclic placement.
Expected Complexity
Time: O(n)
Space: O(1) auxiliary
Follow-up
Can you solve it without an extra hash set?
Practice Notes
Attempts: 0
Time spent: 0min
Hints used: 0
JavaScript
00:00
Loading...
Case 1
Case 2
Case 3
Input
[4,3,2,7,8,2,3,1]Expected
[5,6]