fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin>>n;
  7.  
  8. vector<int> arr(n);
  9. for (int i=0; i<n; i++){
  10. cin>>arr[i];
  11. }
  12.  
  13. int maxf = INT_MIN, minf = INT_MAX, emax, emin;
  14.  
  15. unordered_map<int, int> freq;
  16. for (int x : arr) freq[x]++;
  17.  
  18. for (auto [ele, f] : freq){
  19. if (f > maxf){
  20. maxf = f;
  21. emax = ele;
  22. } if (f < minf){
  23. minf = f;
  24. emin = ele;
  25. }
  26. }
  27. cout<<"Min ELe. : "<<emin<<" Min Freq : "<<minf<<endl;
  28. cout<<"Max Ele. : "<<emax<<" Max Freq : "<<maxf<<endl;
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5284KB
stdin
6
3 2 3 4 2 3
stdout
Min ELe. : 4 Min Freq : 1
Max Ele. : 3 Max Freq : 3