Is Subsequence
EasyP2Coding
Return true if s1 is a subsequence of s2, and false otherwise.
A subsequence keeps the relative order of characters but may skip characters. The empty string is a subsequence of every string.
Example 1
- Input
- s1 = "abc", s2 = "ahbgdc"
- Output
- true
Example 2
- Input
- s1 = "axc", s2 = "ahbgdc"
- Output
- false
Example 3
- Input
- s1 = "", s2 = "abc"
- Output
- true
Constraints
- 0 <= s1.length, s2.length <= 10^5
- Both strings consist of lowercase English letters.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.