AlgoDesign

Nearest repeated entries in array

1import math
2class Solution:
3    def nearestRepeatedEntriesArray(self, words):
4        seen, res = {}, math.inf
5        for i in range(len(words)):
6            if words[i] in seen:
7                res = min(res, i - seen[words[i]])
8            seen[words[i]] = i
9        
10        return res