You are given two strings s and t. Your task is to check whether s is a subsequence of t. A string is called a subsequence if all its characters appear in the same order in the other string, though not necessarily consecutively.
Example 1
Input: s = "ace", t = "abcde"
Output: true
Explanation: Characters a, c, and e appear in the same order in "abcde".
Example 2
Input: s = "aec", t = "abcde"
Output: false
Explanation: Characters are not in the required order.
Example 3
Input: s = "abc", t = "abc"
Output: true
Explanation: Both strings are identical, so it is a subsequence.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
abc axbyc
true
ace abcde
true