Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can be rotated to be equal to another domino.

Return the number of pairs (i, j) for which 0 &lt;= i &lt; j &lt; dominoes.length, and dominoes[i] is equivalent to dominoes[j].

&nbsp;
Example 1:

Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]
Output: 1


Example 2:

Input: dominoes = [[1,2],[1,2],[1,1],[1,2],[2,2]]
Output: 3


&nbsp;
Constraints:


	1 &lt;= dominoes.length &lt;= 4 * 104
	dominoes[i].length == 2
	1 &lt;= dominoes[i][j] &lt;= 9


import math
class Solution:
    def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:
        d=dict()
        for i in dominoes:
            i.sort()            #Just to make everything equal and comparable
            if(tuple(i) in d.keys()):   #In python, lists are unhashable so converted the list into tuples
                d[tuple(i)]+=1
            else:
                d[tuple(i)]=1
        count=0
        for x,y in d.items():
            if(y>1):
				count+=y*(y-1)//2        #To check the number of pairs, if 2 elements pairs is 1,if 3 pair is 3 and so                                                                     on.....formula is n*n-1/2
        return count
                
class Solution {
    /** Algorithm
        1. Brute force cannot be used because of the set size.
        2. Traverse the dominos and group & count them by min-max value.
           As pieces can be from 1 to 9, means their groups will be from 11 to 99.
            eg: [1,2] will be the same as [2,1]. Their value is 10 * (min(1,2)) + max(1,2)
                => 10 * 1 + 2 = 12.
            so pieces[12]++;
        3. After finishing traversing, iterate over the counted pieces and if the count is
          > 1, calculate the combinations of X by 2.
        4. The formula is n!/ (k! * (n-k)!)
           As n! can be very large, use the short version of it; (n * (n-1)) / 2. EG n= 40
           Eg:  40!         simplify this(divide by 38!) 39 * 40
              --------                                  ---------   
               2! * (38!)                                   2
        5. Return the total result      
    */
    public int numEquivDominoPairs(int[][] dominoes) {
        int[] pieces = new int[100];
        for (int[] domino : dominoes) {
            pieces[10 * Math.min(domino[0], domino[1]) + Math.max(domino[0], domino[1])]++;
        }
        int pairs = 0;
        for (int i = 11; i <= 99; i++) {
            if (pieces[i] > 1) {
                pairs += getCombinations(pieces[i]);
            }
        }
        
        return pairs;    
    }
    
    private int getCombinations(int n) {
        return (n * (n-1)) / 2;
    }
}
class Solution {
public:
    int numEquivDominoPairs(vector<vector<int>>& dominoes)
    {
        map<pair<int,int>,int> m;
        int ans=0;
        for(auto &d:dominoes)
        {
            int a=min(d[0],d[1]),b=max(d[0],d[1]);
            m[{a,b}]++;
        }
        for(auto &p:m)
        {
            int n=p.second;
            ans+=((n-1)*n)/2;
        }
        return ans;

    }
};
//if you like the solution plz upvote.
var numEquivDominoPairs = function(dominoes) {
    let map = {};
    let count = 0;
    for (let [a, b] of dominoes) {
        if (b > a) {
            [a, b] = [b, a];
        }
        let key = `${a}-${b}`;
        if (map.hasOwnProperty(key)) {
            map[key]++;
            count += map[key];
        } else {
            map[key] = 0;
        }
    }
    return count;
};
Number of Equivalent Domino Pairs