Number of Equivalent Domino Pairs

Easy

Description

Given a list of dominoes, return the number of pairs (i, j) for which i < j and dominoes[i] is equivalent to dominoes[j]. Dominoes are equivalent if one can be rotated to match the other.

Examples

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

[1,2] and [2,1] are equivalent.

Input:dominoes = [[1]]
Output:1
Explanation:

With only one domino, there are no pairs to compare.

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

[1,1] at indices 0 and 3 form one equivalent pair. [2,3] at index 1 and [3,2] at index 2 are equivalent (another pair). Total: 2 pairs.

Constraints

  • 1 ≤ dominoes.length ≤ 4 * 10^4
  • dominoes[i].length == 2

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!