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