Skip to content

Instantly share code, notes, and snippets.

@thmain
Created June 27, 2017 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/fb8a5d010c8e0463220cc0e5ad4801a3 to your computer and use it in GitHub Desktop.
Save thmain/fb8a5d010c8e0463220cc0e5ad4801a3 to your computer and use it in GitHub Desktop.
public class MaxRepeatingBruteForce {
public void MaxRepeatingElement(int [] arrA){
int maxCounter = 0;
int element=0;
for (int i = 0; i <arrA.length ; i++) {
int counter =1;
for (int j = i+1; j <arrA.length ; j++) {
if(arrA[i]==arrA[j]){
counter++;
}
}
if(maxCounter<counter){
maxCounter=counter;
element = arrA[i];
}
}
System.out.println("Element repeating maximum no of times: " + element + ", maximum count: " + maxCounter);
}
public static void main(String[] args) {
int [] arrA = {4, 1, 5, 2, 1, 5, 9, 8, 6, 5, 3, 2, 4, 7};
MaxRepeatingBruteForce m = new MaxRepeatingBruteForce();
m.MaxRepeatingElement(arrA);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment