2825. Make String a Subsequence Using Cyclic Increments
class Solution:
def canMakeSubsequence(self, str1: str, str2: str) -> bool:
# this should be more naive
# m = len(str1)
# n = len(str2)
# j = 0
# for i in range(m):
# o1 = ord(str1[i])
# o2 = ord(str2[j])
# if o1 == o2 or o2 - o1 == 1 or o1 - o2 == 25:
# j += 1
# if j == n:
# return True
# return False
m = len(str1)
n = len(str2)
j = 0
for i in range(m):
diff = (ord(str1[i]) + 1 - ord('a')) % 26 - (ord(str2[j]) -ord('a')) % 26
if str1[i] == str2[j] or diff == 0:
j += 1
if j == n:
return True
return False