Count how many pairs of dominoes are equivalent when order within each domino does not matter.
Given a list of dominoes, each domino is represented by two numbers. Two dominoes are considered equivalent if one can be rotated to match the other, meaning the pair of values is the same regardless of order.
Your task is to count the number of unordered pairs of equivalent dominoes in the list.
[a, b].(i, j) with i < j such that domino i is equivalent to domino j.Example 1
Input
dominoes = [[1,2],[2,1],[3,4],[5,6]]
Output
1
Explanation
Only the first two dominoes are equivalent, so there is exactly one pair.
Example 2
Input
dominoes = [[1,1],[1,1],[1,1]]
Output
3
Explanation
All three dominoes are equivalent. The number of unordered pairs is C(3,2) = 3.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.