fork download
  1. /**
  2.  * Find the element with maximum frequency
  3.  * @author PRATEEK
  4.  */
  5. class MaxRepeatingNumer {
  6. public static void main(String[] args) {
  7.  
  8. int arr[] = { 3, 1, 3, 2, 1, 2, 2 };
  9. int x = 5;
  10. System.out.println(maxRepeatingNumer(arr, x));
  11. }
  12.  
  13. private static int maxRepeatingNumer(int arr[],int k) {
  14.  
  15. int i = 0, max = arr[0], result = 0;
  16. for (; i < arr.length; i++)
  17. arr[arr[i] % k] += k;
  18.  
  19. i = 1;
  20. for (; i < arr.length; i++) {
  21. if (arr[i] > max) {
  22. max = arr[i];
  23. result = i;
  24. }
  25. }
  26.  
  27. i = 0;
  28. for (; i < arr.length; i++)
  29. arr[i] = arr[i] % k;
  30.  
  31. return result;
  32. }
  33. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
2