Two concise O(n) solutions - with and without LINQ
With almost no LINQ:\ncsharp\npublic int MinDominoRotations(int[] tops, int[] bottoms)\n{\n    // Pass 1: Count domino values and get the most frequent domino v
With almost no LINQ:\n```csharp\npublic int MinDominoRotations(int[] tops, int[] bottoms)\n{\n    // Pass 1: Count domino values and get the most frequent domino value\n    var freq = new int[7];\n    for (int i = 0; i < tops.Length; i++)\n    {          \n        freq[tops[i]]++;\n        freq[bottoms[i]]++;\n    }        \n    var x = Array.IndexOf(freq, freq.Max());\n    \n\t// Pass 2: Check whether the desired arrangement is possible and if so, count how many rotations are needed\n    var rotationsTop = 0;\n    var rotationsBottom = 0;\n    for (int i = 0; i < tops.Length; i++)\n    {\n        if (tops[i] != x && bottoms[i] != x) return -1;\n        if (tops[i] != x) rotationsTop++;\n        if (bottoms[i] != x) rotationsBottom++;\n    }\n    \n    return Math.Min(rotationsTop, rotationsBottom);\n}\n```\n\nWith some LINQ:\n```csharp\npublic int MinDominoRotations(int[] tops, int[] bottoms)\n{\n\t// Pass 1: Get the most frequent domino value ("mode")\n    var x = tops.Concat(bottoms)\n        .GroupBy(v => v)\n        .OrderBy(g => -g.Count())\n        .Select(g => g.Key)\n        .First();\n    \n\t// Pass 2: Check whether the desired arrangement is possible and if so, count how many rotations are needed\n    var rotationsTop = 0;\n    var rotationsBottom = 0;\n    for (int i = 0; i < tops.Length; i++)\n    {\n        if (tops[i] != x && bottoms[i] != x) return -1;\n        if (tops[i] != x) rotationsTop++;\n        if (bottoms[i] != x) rotationsBottom++;\n    }\n    \n    return Math.Min(rotationsTop, rotationsBottom);\n}\n```
['C#']