My interview question was to find duplicates in two arrays.
array1 = [1,2,4,6,9,50,34];
array2 = [1,5,4,50,24,78,34];
I know the code for this is to use two for
loops:
for(int i=0; i<arr1.length; i++){
for(int j=0; j<arr2.length; j++) {
if(arr1[i]==arr2[j]) {
System.out.println(arr1[i]);
}
}
}
The interviewer asked for a better method with much iteration. Can I get any suggestions regarding this?