`{"id":"ed690bde-fc0f-4af5-9e77-b0988b447aca","name":"Minimum Domino Rotations For Equal Row","description":"1. In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. \r\n2. A domino(Dice Structured) is a tile with two numbers from 1 to 6 - one on each half of the tile.\r\n3. We may rotate the ith domino, so that tops[i] and bottoms[i] swap values.\r\n4. 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.\r\n5. If it cannot be done, return -1.\r\n","inputFormat":"tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2]\r\ntops = [3,5,1,2,3], bottoms = [3,6,3,3,4]\r\n","outputFormat":"2\r\nExplanation: \r\nIf 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.\r\n\r\n-1\r\nExplanation: \r\nIn this case, it is not possible to rotate the dominoes to make one row of values equal.","constraints":"1. 2 &lt;= tops.length == bottoms.length &lt;= 2 * 10^4\r\n2. 1 &lt;= tops[i], bottoms[i] &lt;= 6\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n int minDominoRotations(vector<int> tops, vector<int> bottoms) {\n \n return 0;\n }\n\n int main() {\n int n;\n cin>>n;\n vector<int> top(n);\n vector<int> bottom(n);\n\n // read top\n for (int i = 0; i < top.size(); i++) {\n cin>>top[i];\n }\n // read bottom\n for (int i = 0; i < bottom.size(); i++) {\n cin>>bottom[i];\n }\n\n int rotation = minDominoRotations(top, bottom);\n cout<<rotation;\n }"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n //~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~\r\n public static int minDominoRotations(int[] tops, int[] bottoms) {\r\n // write your code here\r\n }\r\n\r\n //~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] top = new int[n];\r\n int[] bottom = new int[n];\r\n\r\n // read top\r\n for (int i = 0; i < top.length; i++) {\r\n top[i] = scn.nextInt();\r\n }\r\n // read bottom\r\n for (int i = 0; i < bottom.length; i++) {\r\n bottom[i] = scn.nextInt();\r\n }\r\n\r\n int rotation = minDominoRotations(top, bottom);\r\n System.out.println(rotation);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n5 3 5 6 2 5 \r\n4 5 4 5 5 5","sampleOutput":"2","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"0a5d44ed-bed8-4383-8bab-06fc5e511376","name":"Minimum Domino Rotations For Equal Row","slug":"minimum-domino-rotations-for-equal-row","type":1}],"next":{"id":"1c937841-c4f7-44e3-8dbf-17148a6f413a","name":"Minimum Domino Rotations For Equal Row","type":3,"slug":"minimum-domino-rotations-for-equal-row"},"prev":{"id":"98648a29-6d65-43c1-a4fe-1ab64b42af0b","name":"3 Sum - Target Sum Unique Triplet MCQ","type":0,"slug":"3-sum-target-sum-unique-triplet-mcq"}}}`

# Minimum Domino Rotations For Equal Row

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.

`{"id":"ed690bde-fc0f-4af5-9e77-b0988b447aca","name":"Minimum Domino Rotations For Equal Row","description":"1. In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. \r\n2. A domino(Dice Structured) is a tile with two numbers from 1 to 6 - one on each half of the tile.\r\n3. We may rotate the ith domino, so that tops[i] and bottoms[i] swap values.\r\n4. 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.\r\n5. If it cannot be done, return -1.\r\n","inputFormat":"tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2]\r\ntops = [3,5,1,2,3], bottoms = [3,6,3,3,4]\r\n","outputFormat":"2\r\nExplanation: \r\nIf 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.\r\n\r\n-1\r\nExplanation: \r\nIn this case, it is not possible to rotate the dominoes to make one row of values equal.","constraints":"1. 2 &lt;= tops.length == bottoms.length &lt;= 2 * 10^4\r\n2. 1 &lt;= tops[i], bottoms[i] &lt;= 6\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n int minDominoRotations(vector<int> tops, vector<int> bottoms) {\n \n return 0;\n }\n\n int main() {\n int n;\n cin>>n;\n vector<int> top(n);\n vector<int> bottom(n);\n\n // read top\n for (int i = 0; i < top.size(); i++) {\n cin>>top[i];\n }\n // read bottom\n for (int i = 0; i < bottom.size(); i++) {\n cin>>bottom[i];\n }\n\n int rotation = minDominoRotations(top, bottom);\n cout<<rotation;\n }"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n //~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~\r\n public static int minDominoRotations(int[] tops, int[] bottoms) {\r\n // write your code here\r\n }\r\n\r\n //~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] top = new int[n];\r\n int[] bottom = new int[n];\r\n\r\n // read top\r\n for (int i = 0; i < top.length; i++) {\r\n top[i] = scn.nextInt();\r\n }\r\n // read bottom\r\n for (int i = 0; i < bottom.length; i++) {\r\n bottom[i] = scn.nextInt();\r\n }\r\n\r\n int rotation = minDominoRotations(top, bottom);\r\n System.out.println(rotation);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n5 3 5 6 2 5 \r\n4 5 4 5 5 5","sampleOutput":"2","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"0a5d44ed-bed8-4383-8bab-06fc5e511376","name":"Minimum Domino Rotations For Equal Row","slug":"minimum-domino-rotations-for-equal-row","type":1}],"next":{"id":"1c937841-c4f7-44e3-8dbf-17148a6f413a","name":"Minimum Domino Rotations For Equal Row","type":3,"slug":"minimum-domino-rotations-for-equal-row"},"prev":{"id":"98648a29-6d65-43c1-a4fe-1ab64b42af0b","name":"3 Sum - Target Sum Unique Triplet MCQ","type":0,"slug":"3-sum-target-sum-unique-triplet-mcq"}}}`

Editor

# 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

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 5 3 5 6 2 5 4 5 4 5 5 5```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}2`

Discussions

Show Discussion

Related Resources