2025-08-21 11:52:44 +0000 UTC

Find the Losers of the Circular Game

Code

class Solution:
    def circularGameLosers(self, n: int, k: int) -> List[int]:
        count = 1
        i = 0
        enc = set((0, ))
        while True:
            i = (i + k * count) % n
            if i in enc:
                break
            enc.add(i)
            count += 1
        res = []
        for i in range(n):
            if i not in enc:
                res.append(i + 1)
        return res