Minimum number of binary flips
\nvar minFlips = function(s) {\n  const lengthOfString = s.length\n  const alternatingPattern = "01"\n  let flipCount = 0\n  for (let index = 0; index < lengthO
```\nvar minFlips = function(s) {\n  const lengthOfString = s.length\n  const alternatingPattern = "01"\n  let flipCount = 0\n  for (let index = 0; index < lengthOfString; ++index) {\n    if (s[index] !== alternatingPattern[index % 2]) {\n      ++flipCount\n    }\n  }\n\n  let minimumFlips = Math.min(flipCount, lengthOfString - flipCount)\n\n  for (let index = 0; index < lengthOfString; ++index) {\n    if (s[index] !== alternatingPattern[index % 2]) {\n      --flipCount\n    }\n\n    if (s[index] !== alternatingPattern[(index + lengthOfString) % 2]) {\n      ++flipCount\n    }\n\n    minimumFlips = Math.min(minimumFlips, flipCount, lengthOfString - flipCount)\n  }\n\n  return minimumFlips\n}\n```
['JavaScript']