fork download
  1. #include <iostream>
  2. #include <climits>
  3. #include <vector>
  4. #include <unordered_map>
  5. using namespace std;
  6. int main() {
  7. vector<int> arr={4,5,6,4,6,6,7,8,5,5};
  8. unordered_map<int,int> f;
  9. for(int n:arr){
  10. f[n]++;
  11. }
  12.  
  13. int m=INT_MAX;
  14. int n=INT_MIN;
  15. for(const auto& x:f){
  16. int f1=x.second;
  17. if(f1<m){
  18. m=f1;
  19. }
  20. if(f1>n){
  21. n=f1;
  22. }
  23. }
  24. cout<<"max freq:"<<m;
  25. cout<<"min freq:"<<n;
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
max freq:1min freq:3