Can some explain why the o/p for "OXOX" is 1 when but I think it should be 2
Here is my implementation which giving output as 2 but the Leetcode compiler is expecting 1\n\n\npublic static int minimumMoves(String s) {\n\n\t\tif (s.indexOf
Here is my implementation which giving output as 2 but the Leetcode compiler is expecting 1\n\n```\npublic static int minimumMoves(String s) {\n\n\t\tif (s.indexOf(\'X\') < 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tchar[] arr = s.toCharArray();\n\t\tint n = arr.length;\n\t\tint count = 0;\n\t\tint start = 0;\n\t\tint end = 0;\n\t\twhile (start < n) {\n\t\t\tif ((start + 3) > arr.length - 1) {\n\t\t\t\tend = n - 1;\n\t\t\t} else {\n\t\t\t\tend = (start + 3) - 1;\n\t\t\t}\n\t\t\tboolean flip = false;\n\t\t\tint ind = start;\n\t\t\twhile (ind <= end) {\n\t\t\t\tif (arr[ind] == \'X\') {\n\t\t\t\t\tarr[ind] = \'O\';\n\t\t\t\t\tflip = true;\n\t\t\t\t}\n\t\t\t\tind++;\n\t\t\t}\n\t\t\tcount += flip ? 1 : 0;\n\t\t\tstart += 1;\n\t\t}\n\n\t\treturn count;\n\n\t}\n```\n\nExplaination : "0X0X"\nfirst 3 characters -> "000" -> s becoms -> "000X" -> res - 1\nnext 3 characters -> "00X" -> s becoms -> "0000" -> res - 2,\n\nis my understanding clear?
[]