fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int a[5]={2,4,7,1,5};
  7. int b[3]={5,4,2};
  8. unordered_map<int,int>m;
  9. for(int i=0;i<5;i++){
  10. m[a[i]]++;
  11. }
  12. for(int i=0;i<3;i++){
  13. if(m[b[i]]==0){
  14. cout<<"there does not exit subarray";
  15. return 0;
  16. }
  17. m[b[i]]--; //decrease count by 1 as we have matched it with current arr2[i]
  18.  
  19. }
  20. cout<<"there exit the subarray"<<endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
there exit the subarray