Problem statement

https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/

Solution

We just need to check if gcd of all frequencies is not equal to 1.

Complexity

It is O(n) for time and space if we assume that gcd is O(1) or O(n log M) in other case where M = 2**32

Code

class Solution:
    def hasGroupsSizeX(self, deck):
        return reduce(gcd, list(Counter(deck).values())) != 1