fork download
  1. class Solution {
  2. public:
  3. int numberOfSubarrays(vector<int>& v, int k) {
  4.  
  5. unordered_map<int ,int> m;
  6.  
  7. for(int i=0;i<v.size();++i)
  8. {
  9. if(v[i]&1)
  10. v[i]=1;
  11.  
  12. else
  13. v[i]=0;
  14. }
  15.  
  16. int sum=0,i,cnt=0;
  17. for(i=0;i<v.size();++i)
  18. {
  19. sum+=v[i];
  20. if(sum==k)
  21. cnt++;
  22.  
  23. if(m.find(sum-k)!=m.end())
  24. cnt+=m[sum-k];
  25.  
  26. m[sum]++;
  27. }
  28.  
  29. return cnt;
  30.  
  31.  
  32. }
  33. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:27: error: no template named 'vector'
    int numberOfSubarrays(vector<int>& v, int k) {
                          ^
prog.cpp:5:10: error: use of undeclared identifier 'unordered_map'
         unordered_map<int ,int> m;
         ^
prog.cpp:5:28: error: expected '(' for function-style cast or type construction
         unordered_map<int ,int> m;
                       ~~~ ^
prog.cpp:23:16: error: use of undeclared identifier 'm'
            if(m.find(sum-k)!=m.end())
               ^
prog.cpp:23:31: error: use of undeclared identifier 'm'
            if(m.find(sum-k)!=m.end())
                              ^
prog.cpp:24:22: error: use of undeclared identifier 'm'
                cnt+=m[sum-k];
                     ^
prog.cpp:26:13: error: use of undeclared identifier 'm'
            m[sum]++;
            ^
7 errors generated.
stdout
Standard output is empty