""" 0392.1 - Is Subsequence - Solution 1 - Two Pointer """
#####################################################################################
# Imports
#####################################################################################
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def isSubsequence(self, s: str, t: str) -> bool:
"""Is Subsequence Function"""
i, j = 0, 0
while i < len(s) and j < len(t):
if s[i] == t[j]:
i += 1
j += 1
return i == len(s)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().isSubsequence("abc", "ahbgdc")) # True
print(Solution().isSubsequence("axc", "ahbgdc")) # False
print(Solution().isSubsequence("", "ahbgdc")) # True
print(Solution().isSubsequence("abc", "")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0392.2 - Is Subsequence - Solution 2 - Iterator with all() """
#####################################################################################
# Imports
#####################################################################################
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def isSubsequence(self, s: str, t: str) -> bool:
"""Is Subsequence Function"""
iterator = iter(t)
return all(char in iterator for char in s)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().isSubsequence("abc", "ahbgdc")) # True
print(Solution().isSubsequence("axc", "ahbgdc")) # False
print(Solution().isSubsequence("", "ahbgdc")) # True
print(Solution().isSubsequence("abc", "")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()