Question:
MEX Problem
Given an array arr contalning n non-negative integers and an element x, in one operation, x can be added to or subtracted from any element of the array. MEX of an array is defined as the smallest non-negative integer which is not present in the array. For example, the MEX of [0, 1, 1, 3] is 2, and the MEX of [1, 2, 4] is 0.
Find the maximum possible MEX of the array that can be achieved by doing the above operation any number of times.
The question has been solved, Thanks @anarchaworld
I got this question in the Atlassian Coding Test but was unable to solve the question attached below.


Solution:
private int solve(int[] A, int X){
int[] reminder = new int[X];
for (int n : A){
reminder[n%X]++;
}
for (int i = 0; i < A.length; i++){
if (--reminder[i%X]<0){
return i;
}
}
return A.length;
}