C# sliding window solution
Based on the most voted solution by neal99\n\n\npublic int MinMoves(int[] nums, int k)\n{\n\tList<int> p = new List<int>() { 0 }; //extra zero for presum array\
Based on the most voted solution by neal99\n\n```\npublic int MinMoves(int[] nums, int k)\n{\n\tList<int> p = new List<int>() { 0 }; //extra zero for presum array\n\tfor (int i = 0; i < nums.Length; i++)\n\t{\n\t\tif (nums[i] == 1)\n\t\t{\n\t\t\tp.Add(i);\n\t\t}\n\t}\n\tint n = p.Count;\n\tint[] presum = new int[n];\n\tfor (int i = 1; i < n; i++)\n\t{\n\t\tpresum[i] = p[i] + presum[i - 1];\n\t}\n\tint result = Int32.MaxValue;\n   \n   \tfor (int l = 1, r = k; r < n; l++, r++)\n\t{\n\t\tint mid = (l + r) / 2;\n\t\tint radius = mid - l;\n\t\t\n\t\t// presum[r] contains sum of values upto r and presum[mid] contains the sum of values upto mid\n\t\t// if we want to get the sum of mid+1 to r -> presum[r] - presum[mid]\n\t\t// for sum of l to mid-1 use presum[mid-1] - presum[l-1] as l in included\n\t\tint right = presum[r] - presum[mid]; \n\t\tint left = presum[mid - 1] - presum[l - 1];\n\t\t\n\t\t// [1+2+.. +radius] both the sides = (radius*(radius+1)/2)*2 = radius*(1+radius)\n\t\tint substract = (1 + radius) * radius; \n\t\tif (k % 2 == 0)\n\t\t{\n\t       // in case of even k, one extra element on the right will be at (radius+1)th position from mid\n\t\t   // also one extra p[mid] needs to be deleted\n\t\t\tsubstract += p[mid];\n\t\t\tsubstract += (1 + radius);\n\t\t}\n\t\tresult = Math.Min(result, right - left - substract);\n\t}\n\treturn result;\n}\n```
[]