Magician DRK

5

1 votes
Easy
Problem

DRK, the famous magician of MACTLand, had gone outside to visit Fruit Garden. As the order of the MACTLand had decided, the entry to the land was prohibited after 11:00 PM. As he might get late, he decided to bribe the gatekeepers, by telling them about this divine fruit which was very delicious and unique. They agreed to the deal that if he brings a divine fruit for each of the N gatekeepers, then he will be allowed to enter the MACTLand.

As he knows, there is no such thing called divine fruit so he decides to bring N simple fruits of same kind from the garden.

Luckily, There were exactly N trees in a row each of them having one fruit but they were of one of the two kinds RED or GREEN. DRK needed all fruit of same kind so he decided to use his magical powers.

In one second, he can convert all the RED fruits, which are immediate right to GREEN fruits, to GREEN or all the GREEN fruits, which are immediate right to RED fruits, to RED.

You are required to print the minimum number of seconds required by DRK to convert all the FRUITS to one of the colours so that he can go back quickly.

INPUT:

The first line of the input contains a single integer N.

The Second line of the input contains N space separated integers. Each integer is either 0 or 1.

0 denotes RED Fruits, 1 denotes GREEN Fruits.

OUTPUT:

A single integer denoting minimum time required by DRK to convert all the fruit of same kind.

CONSTRAINTS:

1 ≤ N ≤ 1000

Sample Input
10
0 0 1 0 0 0 1 1 0 0
Sample Output
2
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

We can either convert all '0's to '1's or all '1's to '0's

If we try to convert all '1's to '0's, in 1 second, the array becomes

0 0 0 0 0 0 0 1 0 0

after 1 more second

0 0 0 0 0 0 0 0 0 0

So total minimum possible time equals 2 seconds

All the participants need to register on the given link:goo.gl/MDh9FR

Editor Image

?