Preview:
class Solution {
    public boolean hasGroupsSizeX(int[] deck) {
        //make a frequency map 
        HashMap<Integer,Integer> fmap = new HashMap<>();

        for(int val : deck)
        fmap.put(val,fmap.getOrDefault(val,0)+1);

        //iterate the frequency map and find GCD(greatest common divisor) if found then
        //that means they can be divide in GCD groups
        int ans = 0;
        for(int val : fmap.keySet()){

            ans = gcd(ans,fmap.get(val));
        }

        //if gcd is 1 there is no common divisor except 1
        return ans == 1 ? false : true;     
    }

    public int gcd(int a , int b){

        if(b == 0)
        return a;

        return gcd(b , a%b);
    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter