I am struggling with the logic behind solving the following prompt: An unsorted integer array contains 98 different numbers from 1 to 100. So, among the numbers from 1 to 100, two distinct numbers are missing. Find them.
I understand the concept behind finding one missing number, its the second one that's giving me issues. Any suggestions?
Yes, I have seen this entry, but I found the answers given to be either too complex and detailed or off topic. I am a java beginner - just trying to wrap my head around this.
Edit: This is where I am at following initiating an array with numbers 1-100 and then sorting them:
for (int i = 0; i < arr.length; i++) {
int j = i + 1;
if (arr[j] - arr[i] > 1){
int missing = arr[i + 1];
System.out.println(missing);
}
}
My issue now is that I cannot get the loop to print the actual missing number. It prints the number above the missing number. I have tried a few different ways and it always either prints the number above or below, never the actual missing number.