Menu
CoddyTech

Is Subsequence

You get two strings, s and t. Return true if you can turn t into s by deleting some of its letters (possibly none) while the remaining letters keep their order, and false otherwise. For example, ace is a subsequence of abcde, but aec is not.

Function

isSubsequence(s: string, t: string) → boolean
sstring
the string to look for
tstring
the string to delete letters from
Returnsboolean
true if s can be read inside t in order, possibly with gaps

Constraints

  • 1 ≤ s.length ≤ 3 × 104
  • 1 ≤ t.length ≤ 5 × 104
  • s and t contain only lowercase English letters.

Examples

Input
s = "ace"t = "abcde"
Output
true
Explanation
Delete b and d from abcde and ace is left, in the same order.

lock icon+20 hidden tests on Submit

challenge icon

Follow-up

Suppose t stays the same and you have to check a million different strings s against it. How would you prepare t so each check is faster than reading all of t again?

Reset code
def isSubsequence(s, t):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

s = "ace"
t = "abcde"

Expected

true