fork download
  1. import java.util.*;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. //initialize the count of the array size
  8. int n = sc.nextInt();
  9. int[] a = new int[n];
  10.  
  11. for(int i = 0; i < n; i++){
  12. //taking the input for the entire array here
  13. a[i] = sc.nextInt();
  14. }
  15. //considering the min element as 10^-9
  16. int INF = (int)1e9;
  17.  
  18. int finalAnswer1 = INF;
  19. //intialise the max that we can see as 0
  20. int finalAnswer2 = 0;
  21.  
  22. for(int i = 0; i < n; i++){
  23. //initilaize every time as the number may be new every time you move to new index
  24. int count = 0;
  25.  
  26. for(int j = 0; j < n; j++){
  27. //check if the number at the present index i becomes equal while iterating
  28. // over the entire array
  29. if(a[j] == a[i]){
  30. count++;
  31. }
  32. }
  33.  
  34. finalAnswer1 = Math.min(finalAnswer1 , count);
  35. finalAnswer2 = Math.max(finalAnswer2 , count);
  36. }
  37.  
  38. System.out.println(finalAnswer1 + " " + finalAnswer2 );
  39. }
  40. }
Success #stdin #stdout 0.2s 60836KB
stdin
5
1 4 1 4 2
stdout
1 2