#include<iostream> using namespace std; bool is_sub_sequence(char str1[], char str2[], int str1ln, int str2ln) { int j = 0; for (int str1Index = 0; str1Index < str2ln&&j < str1ln; str1Index++) if (str1[j] == str2[str1Index]) { j++; } else { j = 0; //reset the counter } return (j == str1ln); } int main() { char str1[] = "Gla"; char str2[] = "Gilad Darmon"; int str1ln = strlen(str1); int str2ln = strlen(str2); if (is_sub_sequence(str1, str2, str1ln, str2ln)) { cout << "Yes"; } else { cout << "No"; } return 0; }
please comment on performance, except Rabin-Karp algorithm can this be more efficient?