Its very simple , first of all iterate the array and get the sum of all number , As we know sum of natural numbers from 1 to n we can write as n*(n+1)/2. Now we have to subtract the sum of the array from [n*(n+1)/2] .

Here we get the missing number .

See the code example :

int sum = 0; int index = -1;

for (int j = 0; j < array.length; j++) {

if (arr[j] == 0) {

index = i;

} else {

sum += arr[j];

}

}

int total = (array.length + 1) * array.length / 2;

System.out.println("This number is missing...: " + (total - sum) + " at index " + index);

I hope it will help you!