<p>You are given an integer array <code>deck</code> where <code>deck[i]</code> represents the number written on the <code>i<sup>th</sup></code> card.</p>

<p>Partition the cards into <strong>one or more groups</strong> such that:</p>

<ul>
	<li>Each group has <strong>exactly</strong> <code>x</code> cards where <code>x &gt; 1</code>, and</li>
	<li>All the cards in one group have the same integer written on them.</li>
</ul>

<p>Return <code>true</code><em> if such partition is possible, or </em><code>false</code><em> otherwise</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> deck = [1,2,3,4,4,3,2,1]
<strong>Output:</strong> true
<strong>Explanation</strong>: Possible partition [1,1],[2,2],[3,3],[4,4].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> deck = [1,1,1,2,2,2,3,3]
<strong>Output:</strong> false
<strong>Explanation</strong>: No possible partition.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= deck.length &lt;= 10<sup>4</sup></code></li>
	<li><code>0 &lt;= deck[i] &lt; 10<sup>4</sup></code></li>
</ul>

class Solution {
public:
    bool hasGroupsSizeX(vector<int>& deck) {
        // ** this not able to pass the edge cases means i have to use some different approach
        // if(deck.size()==1) return false;
        // map<int,int> mp;
        // for(int i:deck){
        //     mp[i]++;
        // }
        // auto j=mp.begin();
        // int k=j->second;
        // while(k>2){
        //     k=k/2;
        // }
        // for(auto at=mp.begin();at!=mp.end();at++){
         
        //   if(*at!=*j)  return false;

        // }
        // for(auto i:mp){
        //    if(i.second%k!=0)  return false; 
        // }
        
        // return true;
        map<int,int> mp;
        for(int i=0;i<deck.size();i++){
         mp[deck[i]]++;
        }
          auto j=mp.begin();
         int g=j->second;
        for(auto i:mp)
            g=gcd(g,i.second);
    return g>=2;
    }

};
20300