2025-08-16 18:43:20 +0300 MSK
Check Whether Two Strings are Almost Equivalent
Links
Code
class Solution:
def checkAlmostEquivalent(self, word1: str, word2: str) -> bool:
freqs = [0] * 26
for char in word1:
freqs[ord(char) - 97] += 1
for char in word2:
freqs[ord(char) - 97] -= 1
for freq in freqs:
if freq > 3 or freq < -3:
return False
return True