Let\'s say I have the following two arrays:
int[] a = [1,2,3,4,5]; int[] b = [8,1,3,9,4];
I would like to take the first value of array
//O(n log(n)), Linear Space Complexity void findDuplicates(int[] x, int[] y){ Arrays.sort(x); Arrays.sort(y); int i = 0,j = 0; while (i < x.length && j < y.length) { if(x[i] == y[j]){ System.out.println(x[i]); i++; j++; }else if (x[i] < y[j]) i++; else j++; } }