Minimum Suffix Flips

MediumString

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:3
Explanation:

Flip at indices 0, 1, 2.

Input:target = "1010"
Output:4
Explanation:

Starting with "0000", flip suffixes at indices 0, 1, 2, and 3 to reach "1010" in 4 flips.

Input:target = "001"
Output:1
Explanation:

Starting with "000", one flip from index 2 converts it to "001", matching the target in 1 flip.

Constraints

  • 1 ≤ target.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!