Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check String Is Subsequence To Another

Medium Acceptance 75.00% Points 30.00

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.

Hints
Hint 1
N/A
Constraints
  • 1 = length of s, t = 105
  • Both strings contain lowercase English letters only
Companies
Apple Mastercard
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions