Number of Equivalent Domino Pairs

You are given a list of `dominoes`, where `dominoes[i] = [a, b]`. Two dominoes `[a, b]` and `[c, d]` are **equivalent** if one can be rotated to equal the other: either `a == c` and `b == d`, or `a == d` and `b == c`. Return the number of index pairs `(i, j)` with `0 <= i < j < dominoes.length` such that `dominoes[i]` is equivalent to `dominoes[j]`.

30:00

Number of Equivalent Domino Pairs
easy
Free written solution
Topics
Companies

You are given a list of dominoes, where dominoes[i] = [a, b]. Two dominoes [a, b] and [c, d] are equivalent if one can be rotated to equal the other: either a == c and b == d, or a == d and b == c.

Return the number of index pairs (i, j) with 0 <= i < j < dominoes.length such that 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≤4×1041 \leq \text{dominoes.length} \leq 4 \times 10^4

  • dominoes[i].length == 2

  • 1≤dominoes[i][j]≤91 \leq \text{dominoes}[i][j] \leq 9

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"dominoes":[[1,2],[2,1],[3,4],[5,6]]}

Equivalent dominoes are the same tile turned around. Turn every tile so its smaller half comes first, then count tiles per shape.

dominoes

0

1

2

3

piles by shape (smaller half first)

no piles yet

pairs so far

0

Variables
VariableValue
pairs0
DepthFunction Call
Stack empty
0/9