class Solution(object):
def checkDistances(self, s, distance):
"""
:type s: str
:type distance: List[int]
:rtype: bool
"""
d = {}
for i, c in enumerate(s):
if c in d and i - d[c] - 1 != distance[ord(c) - ord('a')]:
return False
d[c] = i
return True