You are given a binary string target of length n. You also have a binary string s of length n that starts as all '0'.
Consider an operation where you choose an index i with 0 <= i < n and toggle every character of s from index i to index n - 1. Toggling changes '0' to '1' and '1' to '0'.
Given that you can perform this operation any number of times, return the minimum number of operations needed to make s equal to target.
Examples
Example 1
Input: target = "10111"
Output: 3
Explanation: Starting from "00000", toggle from index 0 to get "11111", toggle from index 1 to get "10000", toggle from index 2 to get "10111". Three operations are needed.
Example 2
Input: target = "101"
Output: 3
Explanation: Toggle from index 0 to get "111", from index 1 to get "100", and from index 2 to get "101".
Example 3
Input: target = "00000"
Output: 0
Explanation: `s` already equals `target`, so no operations are needed.
Constraints
1≤target.length≤105
target[i] is either '0' or '1'.
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run