2260. Minimum Consecutive Cards to Pick Up

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2260

class Solution:
    def minimumCardPickup(self, cards: List[int]) -> int:
        last = {}
        res = inf
        for i, x in enumerate(cards):
            if x in last:
                res = min(res, i - last[x] + 1)
            last[x] = i
        return -1 if res == inf else res