Skip to content

1128. Number of Equivalent Domino Pairs #1642

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the number of equivalent domino pairs in a given list of dominoes. Two dominoes are considered equivalent if one can be rotated to match the other. We can efficiently count these pairs using a hash map to track the frequency of each standardized domino form.

Approach

  1. Standardize Domino Representation: For each domino [a, b], we standardize its representation by sorting the elements such that the smaller element comes first. This transforms each domino into a key (min(a, b), max(a, b)).
  2. Frequency Counting: Use a hash map (or dictionary) to count the occurrences of each standardized domino key.
  3. Calculate Pairs: For each unique domino key with a frequency c, the number …

Replies: 1 comment 2 replies

Comment options

mah-shamim
May 4, 2025
Maintainer Author

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz May 4, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim May 4, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants