22- Is Subsequence
The problem can be found at the following link: Question Link
My Approach
Initialize an integer variable
i
to 0. This variable will be used to keep track of the current character index in strings
.Iterate through each character
x
in the stringt
using a loop.Inside the loop, compare the current character
x
int
with the character at indexi
in strings
.If the characters match (i.e.,
x
is equal tos[i]
), increment thei
variable by 1 to move to the next character in strings
.Continue this process for all characters in string
t
.After the loop, check if
i
is equal to the length of strings
. If it is, it means that all characters ins
have been found int
in the same order, so returntrue
. Otherwise, returnfalse
because not all characters ins
were found int
in the same order.
Time and Auxiliary Space Complexity
Time Complexity:
O(n)
Auxiliary Space Complexity:
O(1)
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. 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 rishabhv12/Daily-Leetcode-Solution repository.
Last updated