package com.fishercoder.solutions;

import java.util.HashMap;
import java.util.Map;

/**
 * 1128. Number of Equivalent Domino Pairs
 *
 * 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 <= i < j < dominoes.length, and dominoes[i] is equivalent to dominoes[j].
 *
 * Example 1:
 *
 * Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]
 * Output: 1
 *
 * Constraints:
 * 1 <= dominoes.length <= 40000
 * 1 <= dominoes[i][j] <= 9
 * */
public class _1128 {
    public static class Solution1 {
        public int numEquivDominoPairs(int[][] dominoes) {
            int m = dominoes.length;
            Map<Integer, Integer> map = new HashMap<>();
            int count = 0;
            for (int i = 0; i < m; i++) {
                int smaller = Math.min(dominoes[i][0], dominoes[i][1]);
                int bigger = Math.max(dominoes[i][0], dominoes[i][1]);
                int key = smaller * 10 + bigger;
                count += map.getOrDefault(key, 0);
                map.put(key, map.getOrDefault(key, 0) + 1);
            }
            return count;
        }

    }
}

@@ -82,561 +82,8 @@
 p;%0A%0A
-/**%0A * 1128. Number of Equivalent Domino Pairs%0A *%0A * Given a list of dominoes, dominoes%5Bi%5D = %5Ba, b%5D is equivalent to dominoes%5Bj%5D = %5Bc, d%5D 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.%0A * Return the number of pairs (i, j) for which 0 %3C= i %3C j %3C dominoes.length, and dominoes%5Bi%5D is equivalent to dominoes%5Bj%5D.%0A *%0A * Example 1:%0A *%0A * Input: dominoes = %5B%5B1,2%5D,%5B2,1%5D,%5B3,4%5D,%5B5,6%5D%5D%0A * Output: 1%0A *%0A * Constraints:%0A * 1 %3C= dominoes.length %3C= 40000%0A * 1 %3C= dominoes%5Bi%5D%5Bj%5D %3C= 9%0A * */%0A
 publ

refactor 1128