You need to find which number appears twice and which is missing. Count the frequency of each number, then check which count is (duplicate) and which is (missing).
Use a set or frequency map. Iterate from to and check which number is missing from the array.
The expected set is . The actual array has one duplicate and one missing value. Compare the two.