Max Consecutive ON Servers
Amazon operates a network of n machines. Some are currently inactive, while others are active. The engineers managing the infrastructure have access to a specific procedure that allows toggling the states of machines. In one use of this operation, they can select a continuous segment of machines and invert their statuses—turning active to inactive, and inactive to active. Due to certain restrictions, this procedure can be used at most k times.
You are given a binary string machine_status, of length n, where '1' indicates an active machine and '0' represents an inactive one, along with an integer max_flips that denotes the maximum number of operations allowed. Determine the highest possible number of adjacent active machines that can be achieved after at most max_flips operations.
Complete the function getMaxConsecutiveON in the editor.
getMaxConsecutiveON has the following parameters:
String machine_status: states of the servers, '1' represents ON state, '0' represents OFFint max_flips: the maximum number of operations that can be performed
Returns
int: The greatest number of back-to-back active machines achievable using no more than max_flips operations
🌷༊·˚Credit to ˚꒰აBarry ᯓᡣ𐭩໒꒱˚
1Example 1
2Example 2

3Example 3
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 2 * 10^51 ≤ max_flips ≤ 2 * 10^5machine_statuscontains only 0s and 1s