Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Is A Subsequence (Main Thread)

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

Constraints

  • Length of both the strings <= 100000
  • The strings will contain only alphanumeric characters (a-z , A-Z, 0-9)
  • The strings can be empty
  • Expected time complexity : O(n)
  • Expected space complexity : O(1)

You can see the full challenge with visuals at this link.

Challenges • Asked almost 7 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Nov 30, 2017:

This is the main discussion thread generated for Is A Subsequence.