Here is the interview question prompt, presented for reference.
Given two strings, one named sub
and the other str
, determine if sub
is a subsequence of str
.
const str = "barbell"
const sub = "bell"
isASubsequence(sub, str);
// true
For the sake of the exercise, let's assume that these strings only have lower case characters.
What is subsequence? You can think of it as a substring, but the letters don't have to be adjacent. It is formed from the base string by deleting some or none of the characters without affecting the relative positions of the other letters. So this also works:
const str = "chicken"
const sub = "hen"
isASubsequence(sub, str);
// true
100000
a-z , A-Z, 0-9
)O(n)
O(1)
You can see the full challenge with visuals at this link.
Challenges • Asked almost 7 years ago by Jake from AlgoDaily
This is the main discussion thread generated for Is A Subsequence.