Is Subsequence

EasyStringSorting

Description

Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

Examples

Input:s = "abc", t = "ahbgdc"
Output:true
Explanation:

Scanning 'ahbgdc' left to right: find 'a' at index 0, then 'b' at index 2, then 'c' at index 5. All characters of 'abc' found in order.

Input:s = "axc", t = "ahbgdc"
Output:false
Explanation:

Scanning 'ahbgdc': find 'a' at index 0, but 'x' never appears in the remaining string 'hbgdc'. Since 'x' cannot be found, 'axc' is not a subsequence.

Input:s = "", t = "ahbgdc"
Output:true
Explanation:

An empty string is a subsequence of any string.

Constraints

  • 0 ≤ s.length ≤ 100
  • 0 ≤ t.length ≤ 10⁴
  • s and t consist only of lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!