Logic is following

First consider the boundary conditions when array size is 1

Since sequences was having a difference of 1 and expected to start with 0 so we do following

First sort the array

once array is sorted then we know ( except in 1st iteration ) wherever next number is not 1 more than previous number then we found the missing number which is one more than previous number

```
public int MissingNumber(int[] nums) {
int retValue=-1;
if(nums.length==1){
return nums[0]^nums.length;
}
Arrays.sort(nums);
for(int k=0;k<nums.length;k++) {
if(k==0 && nums[k]>0) {
retValue=nums[k]-1;
}
else if(k<nums.length-1 && nums[k]+1!=nums[k+1]) {
retValue=nums[k]+1;
}
}
if (retValue==-1) {
retValue = nums[nums.length-1]+1;
}
System.out.println(retValue);
return retValue;
}
```