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