I have an integer arrayList which is 5, 12, 5, 17, 5, 5, 5, 39 and I tried to find the most repeating number and it works which will print 5.
However, I want to write it by using divide and conquer approach.
Any tips would be helpful (pseudocode, Java code or any help...)
public static void main(String[] args) {
int[] repetitive = { 5, 12, 5, 17, 5, 5, 5, 39 };
int counter = 1;
int temp = 0;
int checker = 1;
Arrays.sort(repetitive);
int cont = repetitive[0];
for (int i = 1; i < repetitive.length; i++) {
if (repetative[i] == repetitive[i - 1] && cont == repetitive[i]) {
counter++;
temp = repetitive[i];
} else if (repetitive[i] == repetitive[i - 1]) {
checker++;
if (checker > counter) {
temp = repetitive[i];
} else if (repetitive[i] != repetitive[i - 1]) {
checker = 1;
}
}
}
System.out.println(temp);
}