
Problem
Solution
Submissions
All Disappeared Numbers
Certification: Basic Level
Accuracy: 0%
Submissions: 0
Points: 5
Write a C program to find all the elements that are missing from an array containing integers from 1 to n, where n is the length of the array. Each integer in the range [1, n] should appear exactly once in the array, but some are missing. Return an array of all the integers in the range [1, n] that do not appear in the input array.
Example 1
- Input: nums = [4, 3, 2, 7, 8, 2, 3, 1]
- Output: [5, 6]
- Explanation:
- The array length is 8, so we expect numbers from 1 to 8.
- After checking the array, we find that 5 and 6 are missing.
- Therefore, the output is [5, 6].
- The array length is 8, so we expect numbers from 1 to 8.
Example 2
- Input: nums = [1, 1]
- Output: [2]
- Explanation:
- The array length is 2, so we expect numbers from 1 to 2.
- The number 1 appears twice, so the number 2 is missing.
- Therefore, the output is [2].
- The array length is 2, so we expect numbers from 1 to 2.
Constraints
- The array length will be in the range [1, 3 * 10^4]
- The integers in the array will be in the range [1, n], where n is the array length
- Each integer may appear multiple times in the array
- Time Complexity: O(n)
- Space Complexity: O(1) excluding the output array
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Consider using the array itself as a hash table
- Mark the presence of each number by manipulating the sign of the value at the corresponding index
- After marking, iterate through the array to find indices where the values are positive
- Those indices (plus 1) represent the missing numbers
- Be careful not to modify the array permanently if needed for further use