Given an array containing 0 & 1 only, You have only 1 operation i.e. you can swap theadjacent elements in the array. Find the minimum number of operationsrequired to sort the given input array.

A = (0,0,1,0,1,0,1,1)

A = (0,0,1,0,1,0,1,1)

Min Operations: 3.

Approach:

Let's start with some of the trivial test cases.

(1,0) -- Number of swaps = 1

(1,1,0) -- Number of swaps = 2

(1,1,0,0) -- Number of swaps = 4

So an important observation comes that given an array of the type

(1, 1, 1, ... n times, 0, 0, 0, .. m times)

Number of swaps = n*m (This is based on the fact that each 0 has to be pushed(swapped) back m number of time)

Approach:

Let's start with some of the trivial test cases.

(1,0) -- Number of swaps = 1

(1,1,0) -- Number of swaps = 2

(1,1,0,0) -- Number of swaps = 4

So an important observation comes that given an array of the type

(1, 1, 1, ... n times, 0, 0, 0, .. m times)

Number of swaps = n*m (This is based on the fact that each 0 has to be pushed(swapped) back m number of time)