Skip to main content
Back to problems
Leetcode
Medium
Arrays
Hash Maps
Combinatorics
Number Of Equivalent Domino Pairs

Count how many pairs of dominoes are equivalent when order within each domino does not matter.

Acceptance 0%
Problem Statement

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.

Input Format

  • An array of dominoes, where each domino is a pair of integers [a, b].
  • Each pair represents the two values on a domino.

Output Format

  • Return an integer: the number of pairs (i, j) with i < j such that domino i is equivalent to domino j.

Constraints

  • Domino values are assumed to be small non-negative integers.
  • The number of dominoes can be large enough that an O(n2)O(n^2) approach may be too slow.
  • A pair is counted once, even if more than two identical dominoes exist.
Examples
Sample cases returned by the problem API.

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

Unlock deeper context for this problem

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.