Is Subsequence
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
sandt: two strings.- returns
trueifsis a subsequence oft: what is left oftonce some of its characters (maybe none) are deleted, the rest in their order; otherwisefalse.- constraints
- 0 ≤ s.length ≤ 100
- 0 ≤ t.length ≤ 10⁴
- s, t: lowercase English letters
- 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
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more two pointers problems
- 125Valid PalindromeEasysolve
- 26Remove Duplicates from Sorted ArrayEasysolve
- 283Move ZeroesEasysolve
- 88Merge Sorted ArrayEasysolve
- 27Remove ElementEasysolve
- 167Two Sum II - Input Array Is SortedMediumsolve
- 153SumMediumsolve
- 11Container With Most WaterMediumsolve
- 80Remove Duplicates from Sorted Array IIMediumsolve
- 189Rotate ArrayMediumsolve
- 151Reverse Words in a StringMediumsolve
- 5Longest Palindromic SubstringMediumsolve
- 42Trapping Rain WaterHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.