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 \(1 \le i,j \le N\)
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:
\(1 \le N \le 10^{5}\)
\(1 \le array[i] \le 10^{5}\)
\(1 \le K \le 10^{5}\)
We need to bring 5,3 and 4 together. So swap 5 and 1.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor