Find the repeating and the missing number
Coding problemMediumAsked in: Amazon, Apple, Bloomberg, Google, Meta, Microsoft
A list holds n numbers, each between 1 and n. Exactly one number appears twice, and because of that exactly one number from 1 to n is missing. The list is in any order.
Return two values: the number that appears twice, then the number that is missing.
Examples
Example 1
Input: nums = [3,1,2,5,3]
Output: [3,4]
Example 2
Input: nums = [1,1]
Output: [1,2]
Example 3
Input: nums = [2,2]
Output: [2,1]
Constraints
- n is between 2 and 100,000
- Every value is between 1 and n
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.