Javascript O(n)
\nvar minDominoRotations = function (A, B) {\n  const numberOfA = new Array(7).fill(0);\n  const numberOfB = new Array(7).fill(0);\n  const same = new Array(7).
```\nvar minDominoRotations = function (A, B) {\n  const numberOfA = new Array(7).fill(0);\n  const numberOfB = new Array(7).fill(0);\n  const same = new Array(7).fill(0);\n  for (let i = 0; i < A.length; i++) {\n    numberOfA[A[i]]++;\n    numberOfB[B[i]]++;\n    if (A[i] == B[i]) same[A[i]]++;\n  }\n  for (let i = 1; i <= 6; i++) {\n    if (numberOfA[i] + numberOfB[i] - same[i] == A.length) {\n      return Math.min(numberOfA[i] - same[i], numberOfB[i] - same[i]);\n    }\n  }\n  return -1;\n}\n```
['JavaScript']