Beats 100.00% Java Solutions | T.C. O(N) | Constant Space | Simple and easy to understand approach
```\n\nclass Solution {\n    public int opsRequired(int[] picked, int[] helper, int targetValue) {\n        int ops = 0;\n        for(int i = 0; i < picked.leng
```\n\nclass Solution {\n    public int opsRequired(int[] picked, int[] helper, int targetValue) {\n        int ops = 0;\n        for(int i = 0; i < picked.length; i++) {\n            //already target value is present\n            if(picked[i] == targetValue)\n                continue;\n            //swap with helper array in case helper has targetValue at current index\n            else if(helper[i] == targetValue)\n                ops++;\n            //not possible to achieve targetValue at current index\n            else\n                return Integer.MAX_VALUE;\n        }\n        return ops;\n    }\n    \n    public int minDominoRotations(int[] A, int[] B) {\n        int minOps = Integer.MAX_VALUE;\n        for(int value = 1; value <= 6; value++) { \n            minOps = Math.min(minOps, opsRequired(A, B, value));\n            minOps = Math.min(minOps, opsRequired(B, A, value));\n        }\n            \n        return minOps != Integer.MAX_VALUE ? minOps : -1;\n    }\n}
['Java']