fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. bool flag=false;
  6. int arr1[]={6,7,3,2,2};
  7. int arr2[]={6,7,2,2,2};
  8. int m=sizeof(arr1)/sizeof(arr1[0]);
  9. int n=sizeof(arr2)/sizeof(arr2[0]);
  10. unordered_map<int, int> mp;
  11. for(int i=0;i<m;i++){
  12. mp[arr1[i]]++;
  13. }
  14. for(int j=0;j<n;j++){
  15. if(mp.find(arr2[j])==mp.end()){
  16. cout<<"arr2 is not a subset of arr1";
  17. flag=true;
  18. }
  19. else if(mp[arr2[j]]==0){
  20. cout<<"arr2 is not a subset of arr1";
  21. flag=true;
  22. }
  23. else{
  24. mp[arr2[j]]--;
  25. }
  26. }
  27. if(flag==false)
  28. cout<<"arr2 is a subset of arr1";
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
arr2 is not a subset of arr1