You have a string s containing only ones and zeroes. Your goal is to make all the characters in s equal using a minimal number of operations. A single operation consists of inverting all the characters in a contiguous substring of s. Inverting a character means transforming a one into a zero, and vice versa.
For example, consider the string "0001100" (quotes for clarity). We can transform this string into all ones using 2 operations:
Invert the entire string: 0001100 -> 1110011.
Invert the substring from the 4th character to the 5th character, inclusive: 1110011 -> 1111111.
We can transform the same string into all zeros using just 1 operation:
Thus, the answer for s="0001100" is 1.
Invert the substring from the 4th character to the 5th character, inclusive: 0001100 -> 0000000.
You are given s as a String. Concatenate the elements of s to obtain the actual string, and return the minimal number of operations necessary to transform s into all ones or all zeroes.