A set originally held every integer from 1 to n, but one number was overwritten by a copy of another, so one value now appears twice and another is missing. Given the resulting array nums, return [the number that occurs twice, the number that is missing].
A set originally held every integer from 1 to n, but one number was overwritten by a copy of another, so one value now appears twice and another is missing. Given the resulting array nums, return [the number that occurs twice, the number that is missing].
Example 1:
Input: {"nums":[1,2,2,4]}
Output: [2,3]
Constraints:
2≤nums.length≤104
1≤nums[i]≤104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,2,4]}
Box i holds a sign flag for the number i + 1. Reading a value v flips box v - 1 negative, so a box that is already negative means v showed up twice.