In a deck of cards, each card has an integer written on it.

Return true if and only if you can choose X &gt;= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where:


	Each group has exactly X cards.
	All the cards in each group have the same integer.


&nbsp;
Example 1:

Input: deck = [1,2,3,4,4,3,2,1]
Output: true
Explanation: Possible partition [1,1],[2,2],[3,3],[4,4].


Example 2:

Input: deck = [1,1,1,2,2,2,3,3]
Output: false
Explanation: No possible partition.


&nbsp;
Constraints:


	1 &lt;= deck.length &lt;= 104
	0 &lt;= deck[i] &lt; 104


class Solution:
    def hasGroupsSizeX(self, deck: List[int]) -> bool:
        
        
        f=defaultdict(int)
        
        for j in deck:
            f[j]+=1
           
        
        import math
        
        u=list(f.values())
        
        g=u[0]
        
        for j in range(1,len(u)):
            g=math.gcd(g,u[j])
        return g!=1
      
        
// X of a Kind in a Deck of Cards
// Leetcode problem : https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/

class Solution {
    public boolean hasGroupsSizeX(int[] deck) {
        int[] count = new int[10000];
        for(int i : deck)
            count[i]++;
        int gcd = 0;
        for(int i : count)
            if(i != 0)
                gcd = gcd == 0 ? i : gcd(gcd, i);
        return gcd >= 2;       
    }
    private int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
}
class Solution {
public:
    int gcd(int a,int b)
    {
        while(a>0 && b>0)
        {
            if(a>b) a=a%b;
            else b=b%a;
        }
        return (a==0? b:a);
    }
    bool hasGroupsSizeX(vector<int>& deck) {
        unordered_map<int,int> mp;
        vector<int> v;
        for(auto i:deck)
        {
            mp[i]++;
        }
        for(auto it:mp)
        {
            v.push_back(it.second);
        }
        int g=-1;
        for(int i=0;i<v.size();i++)
        {
            if(g==-1)
                g=v[i];
            else 
                g=gcd(g,v[i]);
        }
        return g>1;
    }
};
var hasGroupsSizeX = function(deck) {
    let unique = [...new Set(deck)], three = 0, two = 0, five = 0, size = 0, same = 0, s = 0;

    for(let i = 0; i<unique.length; i++){
        for(let y=0; y<deck.length; y++){
            if(unique[i] === deck[y]){
                size++;
            }
        }
        if(size<2) return false;
        if(size%2===0) two++;
        if(size%3===0) three++;
        if(size%5===0) five++;
        if(s === size) same++;
        s = size;
        size = 0;
    }

    if(Math.max(two,three,five) !== unique.length && same !== unique.length-1) return false;
    return true;
};
X of a Kind in a Deck of Cards