Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Check String Is Subsequence To Another

Medium Acceptance 75% Points 30

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.

Examples
Example 1

Example 1

Input: s = "ace", t = "abcde"

Output: true

Explanation: Characters a, c, and e appear in the same order in "abcde".

Example 2

Example 2

Input: s = "aec", t = "abcde"

Output: false

Explanation: Characters are not in the required order.

Example 3

Example 3

Input: s = "abc", t = "abc"

Output: true

Explanation: Both strings are identical, so it is a subsequence.

Constraints
  • 1 = length of s, t = 105
  • Both strings contain lowercase English letters only
Topics
Recursion
Companies
Apple Mastercard
Added 19 Jul 2026 75% acceptance
Ln 1, Col 1Sign in to save your code
abc axbyc
true