class Solution: def checkDistances(self, s: str, distance: List[int]) -> bool: for l in sorted(set(s)): if distance[ord(l)-97] != s.rfind(l) - s.find(l) - 1: return False return True