Question

Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

Ideas

  • Pretty trivial, 5 minute solution, would be faster but we need to keep the relative position of the subsequence. This kind of using the same idea as Leetcode - Maximum Number of Balloons where we think of the letters in s as a currency and make a condition to pass each letter. If we go out of bounds of s, then it is a subsequence.

Solution