Is Subsequence

Problem Summary

(Write in your own words, not copied from LeetCode. This forces comprehension.)

Key Observations

(Patterns, constraints, or hints in the problem statement.)

Main Concepts Used

(Mark the CS concepts or algorithms used.)

Time & Space Complexity

Code

class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        # left, right = 0, 0

        # while left < len(s):
        #     while right < len(t) and s[left] != t[right]:
        #         right += 1
            
        #     if right == len(t):
        #         return False
        #     left += 1
        #     right += 1

        # return True

        pointer = 0
        for char in s:
            while pointer < len(t) and char != t[pointer]:
                pointer += 1
                
            if pointer == len(t):
                return False
            pointer += 1
        return True