Given a binary string (0, 1), you need to find two positions i & j (i <= j) such that when you flip all the characters from i to j, the number of 1 in the binary string is maximized. Flipping here means that 0 becomes 1 and 1 becomes 0. Return an empty array of integer if you cannot find the two indices.
The Analysis
The tricky part of this problem is to know how to assign the cost at each position. When we flip a 0 to 1, we will gain one 1, but when we flip a 1 to 0 we lose one 1. Thus the cost for 0 is 1 and the cost for 1 is -1.
Once we are done with assigning costs, we can easily find the subarray that gives us the highest value.