|
| 1 | +<p>In a row of dominoes, <code>tops[i]</code> and <code>bottoms[i]</code> represent the top and bottom halves of the <code>i<sup>th</sup></code> domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)</p> |
| 2 | + |
| 3 | +<p>We may rotate the <code>i<sup>th</sup></code> domino, so that <code>tops[i]</code> and <code>bottoms[i]</code> swap values.</p> |
| 4 | + |
| 5 | +<p>Return the minimum number of rotations so that all the values in <code>tops</code> are the same, or all the values in <code>bottoms</code> are the same.</p> |
| 6 | + |
| 7 | +<p>If it cannot be done, return <code>-1</code>.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | +<img alt="" src="https://assets.leetcode.com/uploads/2021/05/14/domino.png" style="height: 300px; width: 421px;" /> |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2] |
| 14 | +<strong>Output:</strong> 2 |
| 15 | +<strong>Explanation:</strong> |
| 16 | +The first figure represents the dominoes as given by tops and bottoms: before we do any rotations. |
| 17 | +If we rotate the second and fourth dominoes, we can make every value in the top row equal to 2, as indicated by the second figure. |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> tops = [3,5,1,2,3], bottoms = [3,6,3,3,4] |
| 24 | +<strong>Output:</strong> -1 |
| 25 | +<strong>Explanation:</strong> |
| 26 | +In this case, it is not possible to rotate the dominoes to make one row of values equal. |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p> </p> |
| 30 | +<p><strong>Constraints:</strong></p> |
| 31 | + |
| 32 | +<ul> |
| 33 | + <li><code>2 <= tops.length <= 2 * 10<sup>4</sup></code></li> |
| 34 | + <li><code>bottoms.length == tops.length</code></li> |
| 35 | + <li><code>1 <= tops[i], bottoms[i] <= 6</code></li> |
| 36 | +</ul> |
0 commit comments