Question
Circular Team Huddle
A circular row contains
In one operation, you may swap the positions of any selected employee and any unselected employee. Find the minimum number of swaps needed so that all selected employees occupy consecutive positions on the circle.
If there are fewer than two selected employees, the answer is
Input
The first line contains KaTeX can only parse string typed expression.
The second line contains KaTeX can only parse string typed expression integers, each either 0 or 1.
Output
Print the minimum number of swaps required.
Example
Input:
There are three selected employees. Because the row is circular, positions near the end and beginning may belong to the same block. A block of length 3 can contain two selected employees already, so one swap is sufficient.
7
1 0 1 0 1 0 0Output:1Explanation:There are three selected employees. Because the row is circular, positions near the end and beginning may belong to the same block. A block of length 3 can contain two selected employees already, so one swap is sufficient.