Find the one duplicated number and the one missing number in an array that should contain the integers from 1 to n.
You are given an array of length containing numbers from $1n$. Exactly one number appears twice, and exactly one number is missing.
Return the duplicated number and the missing number.
nums of length n.1..n.Return an array/list of two integers [duplicate, missing].
1..n.1..n does not appear.Example 1
Input
nums = [1,2,2,4]
Output
[2,3]
Explanation
The number 2 appears twice, and 3 is missing from the range 1..4.
Example 2
Input
nums = [3,1,2,5,3]
Output
[3,4]
Explanation
The number 3 is duplicated, and 4 is missing.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.