Interesting String Question | JPMorgan

You are given a string with 1's and 0's you need to return the number of changes needed so that you have x number of 1's before 0's where 0<=x<=length of string

Example:
1010
Answer
1
Explanation
convert the 2nd zero to 1 to get 1110, or the 3rd 1 to 0 to get 1000

It must be in O(n)

Any Suggestions ?

Comments (7)