fork download
  1. #include <iostream>
  2. #include<vector>
  3. #include<climits>
  4. #include<unordered_map>
  5. using namespace std;
  6.  
  7. int main() {
  8. // your code goes here
  9. vector<int> arr={1,2,3,2,3,1,1};
  10. int maxAns=INT_MIN;
  11. int minAns=INT_MAX;
  12. int minElement=0;
  13. int maxElement=0;
  14.  
  15. unordered_map<int,int> m;
  16.  
  17. for(int i=0;i<arr.size();i++) {
  18. m[arr[i]]++;
  19. }
  20.  
  21. for(auto it=m.begin();it!=m.end();it++) {
  22. int count=it->second;
  23. int number=it->first;
  24.  
  25. if(count<minAns) {
  26. minAns=count;
  27. minElement=number;
  28. }
  29.  
  30. if(count>maxAns) {
  31. maxAns=count;
  32. maxElement=number;
  33. }
  34. }
  35.  
  36. cout<<maxElement<<" "<<maxAns<<endl;
  37. cout<<minElement<<" "<<minAns<<endl;
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
1 3
3 2