I got a test on codility for a job interview yesterday. This is the second question and I still can't figure out the solution. You have to find the bug in the code without removing or adding lines. I added a while loop it compiled fine but didn't change much. Any solutions?
import java.util.*;
class minimum {
int minimum(int[] A, int[] B) {
int n = A.length;
int m = B.length;;
Arrays.sort(A);
Arrays.sort(B);
int i = 0;
for (int k = 0; k < n; k++) {
if (i < m - 1 && B[i] < A[k])
i += 1;
if (A[k] == B[i])
return A[k];
}
return -1;
}
}