Swaps

3

1 votes
Mathematics, Easy, Mathematics, Mathamatics
Problem

You are given an array of N numbers and a number K. Find the minimum number of swaps required to bring all the numbers greater than or equal to K together.

Swap here means, swapping value of array[i] and array[j], where 1i,jN

Input Format:

First line contains an integer N, denoting the number of elements in the array.
Second line contains N space-separated integers, denoting the elements of array.

Output Format:
Print the minimum number of swaps required.

Constraints:

1N105
1array[i]105
1K105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We need to bring 5,3 and 4 together. So swap 5 and 1.

Editor Image

?