Skip to content

Instantly share code, notes, and snippets.

@cloverich
Created October 12, 2020 19:57
Show Gist options
  • Save cloverich/9865999e8a5885a6b2a21e3e3be3ec9d to your computer and use it in GitHub Desktop.
Save cloverich/9865999e8a5885a6b2a21e3e3be3ec9d to your computer and use it in GitHub Desktop.
Subsequence problem. I solved this problem while in a meeting, trying to understand how difficult it would be.
function isSubsequence(s: string, t: string): boolean {
let aIdx = 0;
let bIdx = 0;
while ((aIdx < s.length) && (bIdx < t.length)) {
const aChar = s.charAt(aIdx);
const bChar = t.charAt(bIdx);
if (aChar === bChar) {
aIdx++;
}
bIdx++;
}
return aIdx === s.length;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment