Minimum Number of Changes to Make Binary String Beautiful

Medium Topics Company Tags

Change the fewest bits in the even-length string s so that it can be divided into nonempty blocks, each with an even length and only one kind of bit. Different blocks may use different bits. Return the minimum number of changed positions.

Example 1:

Input: s = "00"

Output: 0

Explanation: The whole string is one even-length block of equal bits, so no change is needed.

Example 2:

Input: s = "01"

Output: 1

Explanation: Change either bit to make "00" or "11". The resulting length-2 block is valid.

Example 3:

Input: s = "10"

Output: 1

Explanation: Change either bit to obtain "00" or "11". One change is enough, while the original unequal pair is invalid.

Constraints:

  • 2 <= s.length <= 100000
  • Each character is 0 or 1. The length of s is even.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.