Created
October 12, 2020 19:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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