Official algorithmic problem description and constraints.
A binary string π of length π is given. A binary string is a string consisting only of the characters '1' and '0'.
You can choose an integer π (1β€πβ€π) and then apply the following operation any number of times: choose π consecutive characters of the string and invert them, i.e., replace all '0' with '1' and vice versa.
Using these operations, you need to make all the characters in the string equal to '1'.
Find the maximum value of π for which it is possible to make all the characters in the string equal to '1' using the described operations. Note that the number of operations required to achieve this is not important.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.