Is Subsequence

Given two strings s and t, return true if s is a subsequence of t, and false otherwise. A subsequence is what remains after deleting zero or more characters from a string without changing the order of the rest; for example "ace" is a subsequence of "abcde" but "aec" is not.

30:00

Is Subsequence
easy
Free written solution
Topics
Companies

Given two strings s and t, return true if s is a subsequence of t, and false otherwise. A subsequence is what remains after deleting zero or more characters from a string without changing the order of the rest; for example "ace" is a subsequence of "abcde" but "aec" is not.

Example 1:
Input: {"s":"abc","t":"ahbgdc"}
Output: true
Constraints:
  • 0≤s.length≤1000 \leq s.\text{length} \leq 100

  • 0≤t.length≤1040 \leq t.\text{length} \leq 10^4

  • s and t consist only of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"abc","t":"ahbgdc"}

i = 0 points at 'a', the first character of s still to be found in t.

thread s through t

s

t

a
b
c

▲i

a
h
b
g
d
c

0

1

2

3

4

5

i = 0 (s[i] = 'a')
j = -
found 0/3
Variables
VariableValue
i0
len(s)3
len(t)6
DepthFunction Call
Stack empty
0/9