Given 2 strings like bangalore and blr, return whether one appears as a subsequence of the other. The above case returns true whereas bangalore and brl returns false.
Greedy strategy should work for this problem.
Here is a sample code in C++:
#include
#include
using namespace std;
int main() {
string txt = "quick brown fox jumps over the lazy dog";
string s = "brownfoxzdog";
int pos = -1;
bool ok = true;
for (int i = 0 ; ok && i != s.size() ; i++) {
ok = (pos = txt.find(s[i], pos+1)) != string::npos;
}
cerr << (ok ? "Found" : "Not found") << endl;
return 0;
}