Sort it (Contest)
Sort it (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Sort it (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
Given an array of N integers containing only 0 or 1. You can do the following operations on the array:
swap elements at two indices
choose one index and change its value from 0 to 1 or vice-versa.
You have to do the minimum number of the above operations such that the final array is non-decreasing. Note Consider 1 based Array-indexingInputThe first line of input contains a single integer N. The second line of input contains N space-separated integers denoting the array. Constraints: 1 ≤ N ≤ 100000 elements of the array are 0 or 1.OutputMinimum number of moves required such that the final array is non- decreasing.ExampleSample Input 1 5 1 1 0 0 1 Sample Output 1 2 Explanation: Swap indices (1, 3) Swap indices (2, 4) Sample Input 2 5 0 0 1 1 1 Sample Output 2 0
link: