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 ᯓᡣ𐭩໒꒱˚
machine_status = "00010" max_flips = 1 return = 4
machine_status = "1001" max_flips = 2 return = 4

machine_status = "11101010110011" max_flips = 2 return = 8
1 ≤ n ≤ 2 * 10^51 ≤ max_flips ≤ 2 * 10^5machine_statuscontains only 0s and 1s
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int getMaxConsecutiveON(String server_states, int max_flips) {
// write your code here
}