22- Is Subsequence
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
Initialize an integer variable i
to 0. This variable will be used to keep track of the current character index in string s
.
Iterate through each character x
in the string t
using a loop.
Inside the loop, compare the current character x
in t
with the character at index i
in string s
.
If the characters match (i.e., x
is equal to s[i]
), increment the i
variable by 1 to move to the next character in string s
.
Continue this process for all characters in string t
.
After the loop, check if i
is equal to the length of string s
. If it is, it means that all characters in s
have been found in t
in the same order, so return true
. Otherwise, return false
because not all characters in s
were found in t
in the same order.
Time Complexity: O(n)
Auxiliary Space Complexity: O(1)
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.