Ctrl K

Matching Domino Tiles

Easy
You are given a set of domino tiles tiles, where tiles[i] = [a, b] are the numbers on the two halves of tile i. Two tiles match if one can be turned around to look exactly like the other: [a, b] matches both [a, b] and [b, a]. Return the number of index pairs i < j such that tiles[i] and tiles[j] match.
Example 1
tiles=[[3, 5], [5, 3], [3, 3], [2, 6]] → 1

Only [3, 5] and [5, 3] match: just turn the second one around.

Example 2
tiles=[[4, 1], [1, 4], [4, 1], [6, 6]] → 3

Three identical tiles (allowing a turn) form three pairs.

Example 3
tiles=[[9, 9]] → 0
Constraints
  • 1 ≤ len(tiles) ≤ 4·10⁴
  • len(tiles[i]) = 2
  • 1 ≤ tiles[i][j] ≤ 9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyValues One Apart EasyEven Piles of Cards EasyWords From Letter Tiles EasyCommon to Three Sorted Arrays Easy
loading Python…
Input
tiles=[[3, 5], [5, 3], [3, 3], [2, 6]]
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.