Created
June 27, 2017 01:41
-
-
Save thmain/fb8a5d010c8e0463220cc0e5ad4801a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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