
Is Subsequence (easy)
Problem Statement
Given two strings s and t, return true if the string s is a subsequence of the string t. Otherwise, return false.
A subsequence of a string is a new string that can be formed from the original string by eliminating some (can be zero) of the characters without changing the order of the remaining characters.
Examples
-
Example 1:
- Input:
s = "hello",t = "xyhealoloo" - Expected Output: true
- Justification: By removing "x", "y", "a", "o", and the second "o" from
t,scan be obtained while maintaining the original order.
- Input:
-
Example 2:
- Input:
s = "axc",t = "ahbgdc" - Expected Output: false
- Justification: There is no way to remove characters from
tto achieveswithout altering the sequence of "axc".
- Input:
-
Example 3:
- Input:
s = "abc",t = "aabc" - Expected Output: true
- Justification: By removing the first "a" in
t,sis formed while preserving the character sequence.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory