Description
Given a binary string, flip all characters from any index to end to change 0s to 1s. Return minimum flips to make all 1s.
Examples
Input:
target = "10111"Output:
3Explanation:
Flip at indices 0, 1, 2.
Input:
target = "1010"Output:
4Explanation:
Starting with "0000", flip suffixes: flip from index 0 to get "1111", flip from index 1 to get "1000", flip from index 2 to get "1011", flip from index 3 to get "1010". Total: 4 flips.
Input:
target = "001"Output:
2Explanation:
Starting with "000", one flip from index 2 converts it to "001", matching the target in just 1 flip. The output of 2 indicates the minimum flips required is 2.
Constraints
- •
1 ≤ target.length ≤ 10⁵