def find_shortest_range(gems):
    unique_count = len(set(gems))
    count = {}
    left = 0

    best = (0, len(gems)-1)

    for right in range(len(gems)):
        count[gems[right]] = count.get(gems[right], 0) + 1

        while len(count) == unique_count:
            if right - left < best[1] - best[0]:
                best = (left, right)

            count[gems[left]] -= 1
            if count[gems[left]] == 0:
                del count[gems[left]]
            left += 1

    return (best[0] + 1, best[1] + 1)

gems = ["DIA","RUBY","RUBY","DIA","DIA","EMERALD","SAPPHIRE","DIA"]
print(find_shortest_range(gems))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: