fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Main
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14. int n = sc.nextInt();
  15. int[] arr = new int[n];
  16. for(int i=0;i<n;i++){
  17. arr[i] = sc.nextInt();
  18. }
  19.  
  20. int maxelement=0,maxcount=0,minelement=0,mincount=Integer.MAX_VALUE;
  21. for(int i=0;i<n;i++){
  22. int count=0;
  23. for(int j=0;j<n;j++){
  24. if(arr[i]==arr[j]){
  25. count++;
  26. }
  27. }
  28. if(maxcount<count){
  29. maxcount=count;
  30. maxelement=arr[i];
  31. }
  32. if(mincount >count){
  33. mincount=count;
  34. minelement=arr[i];
  35. }
  36. }
  37. System.out.println(maxcount);
  38. System.out.println(mincount);
  39. }
  40. }
Success #stdin #stdout 0.18s 54624KB
stdin
5
1 2 2 3 3
stdout
2
1