Is Subsequence

Easy#392two arrays

You get two strings, a short one and a long one. Find out whether you can get the short one from the long one by crossing out some of its letters, without changing the order of the rest. Our examples: "cat" in "chart" — yes; "tac" in "chart" — no.

input
s and t: two strings.
returns
true if s is a subsequence of t: what is left of t once some of its characters (maybe none) are deleted, the rest in their order; otherwise false.
constraints
  • 0 ≤ s.length ≤ 100
  • 0 ≤ t.length ≤ 10⁴
  • s, t: lowercase English letters
our 14 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
function isSubsequence(s, t) {

}
Ctrl ↵
format
reset

saved in this browser

14 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more two pointers problems

Pattern “Two pointers” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.