Here I offer you two approaches:
1. Use a
BitArray[
^] and set the bit corresponding to the current number of the array you are iterating over, but test before you set because if it already is set you'll have your duplicate entry. After you're done with your array iterate over the BitArray to find the bit that isn't set. The index of this bit is the number that was missing from the array.
2. Sort your array in ascending. Iterate over your array and calculate the current element minus the former element. These cases exist:
- The difference is one -> Everything is fine
- The difference is zero -> You've found your duplicate
- The difference is two -> You've found the missing element (former element + 1 or current element - 1)
That's really quite easy to implement.
Regards,
— Manfred