We’re preparing your current view and syncing the latest data.
You are given an integer array nums representing the data status of a set that originally contains numbers from 1 to n. Due to an error, one of the numbers in the set is duplicated and another number is missing. Find the number that occurs twice and the number that is missing, and return them as an array.
An integer array nums of length n containing numbers from 1 to n with one number duplicated and one missing.
Return an array of two integers where the first integer is the duplicated number and the second is the missing number.
2 <= nums.length <= 10^4 1 <= nums[i] <= nums.length
Example 1
Input
[1,2,2,4]
Output
[2,3]
Explanation
The number 2 occurs twice and the number 3 is missing.
Find the Missing and Repeating Number
gfg · Similar problem involving finding one missing and one repeating number in an array