JPMorgan ChaseOA #32
How Many Flips?
Estimated EasyJudge-ready
Start with an all-0 string of the same length. Each step picks one position and toggles 0/1 at that position and every position to its right. Find the minimum number of steps to obtain the target.
Input
The first line contains the length n, and the second line contains the binary target string; an empty string is written as an empty line. Original bounds: Unknown. This site uses 0≤n≤200000; the catalog's 100,000 bound is not original evidence.
Output
Output a single integer answer.
Example 1
Input:
5
01011
Output:
3
Example 2
Input:
0
Output:
0
Example 3
Input:
3
111
Output:
1
Example notes
The outputs of the three public examples are, in order: 3; 0; 1. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…