Beautiful Set

There is a set of coins placed on a board. Some coins are placed in a way that the HEAD will be at the top and some coins are placed in an opposite way. HEAD facing coins can be considered as 1 and TAIL facing coins can be considered as 0.

If the coins are arranged in such a manner that all the HEAD facing coins comes first followed by the TAIL facing coins, then the set is called a Beautiful set.

Example: 10100

Beautiful Set : 11100

You need to write a function that takes a 0-1 string as input and return the minimum number of flips needed to make the coins as a beautiful set.

Example1:

Input:

"10100"

Output:

1

Explanation:
In the above set of coins, a beautiful set can be obtained by flipping the second coin.

10100 -> 11100

The minimum number flips needed to make a beautiful set is "1".

Example2:

Input:

"100100"

Output:

1

Example3:

Input:

100001110010

Output:

4

Example4:

Input:

000001

Output:

2

Example5:

Input:

111100

Output:

0




Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.