Minimum Domino Rotations For Equal Row
easy
1. In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. 2. A domino(Dice Structured) is a tile with two numbers from 1 to 6 - one on each half of the tile. 3. We may rotate the ith domino, so that tops[i] and bottoms[i] swap values. 4. Return the minimum number of rotations so that all the values in tops are the same, or all the values in bottoms are the same. 5. If it cannot be done, return -1.
Constraints
1. 2 <= tops.length == bottoms.length <= 2 * 10^4 2. 1 <= tops[i], bottoms[i] <= 6
Format
Input
tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2] tops = [3,5,1,2,3], bottoms = [3,6,3,3,4]
Output
2 Explanation: 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. -1 Explanation: In this case, it is not possible to rotate the dominoes to make one row of values equal.
Example
Sample Input
6
5 3 5 6 2 5
4 5 4 5 5 5
Sample Output
2