fork download
  1. class Solution {
  2. public:
  3. bool isSubSeq(string& a, string& b)
  4. {
  5. int i=0; // 'i' pointer will point to the characters of the string a
  6. int j=0; // 'j' pointer will point to the characters off the string b
  7.  
  8. while(i<a.size() && j<b.size())
  9. {
  10. if(a[i] == b[j]) // if the characters are matching
  11. {
  12. //simply increment both the pointers
  13. i++;
  14. j++;
  15. }
  16. else // if the characters are not matching
  17. {
  18. j++; // only j++ becoz we have check string A is subsequence of B or not
  19. // we can skip move ahead the characters of 'B' but we can't skip the characters of 'A'
  20. }
  21. }
  22.  
  23. // when all the characters of the 'A' are present in 'B'
  24. // then 'i' pointer will be pointing here s1 = "gksrek" <- here it will be pointing after the while loop ends
  25. if(i == a.size()) // if that is the case then i == a.size()
  26. {
  27. return true ; // we will return true
  28. }
  29. return false; // otherwise we will return false
  30.  
  31. }
  32. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:19: error: ‘string’ has not been declared
     bool isSubSeq(string& a, string& b)
                   ^~~~~~
prog.cpp:3:30: error: ‘string’ has not been declared
     bool isSubSeq(string& a, string& b)
                              ^~~~~~
prog.cpp: In member function ‘bool Solution::isSubSeq(int&, int&)’:
prog.cpp:8:19: error: request for member ‘size’ in ‘a’, which is of non-class type ‘int’
         while(i<a.size() && j<b.size())
                   ^~~~
prog.cpp:8:33: error: request for member ‘size’ in ‘b’, which is of non-class type ‘int’
         while(i<a.size() && j<b.size())
                                 ^~~~
prog.cpp:10:19: error: invalid types ‘int[int]’ for array subscript
             if(a[i] == b[j]) // if the characters are matching
                   ^
prog.cpp:10:27: error: invalid types ‘int[int]’ for array subscript
             if(a[i] == b[j]) // if the characters are matching
                           ^
prog.cpp:25:19: error: request for member ‘size’ in ‘a’, which is of non-class type ‘int’
         if(i == a.size()) // if that is the case then i == a.size()
                   ^~~~
stdout
Standard output is empty