Swaps
Practice
3 (1 votes)
Mathematics
Easy
Mathematics
Mathamatics
Problem
26% Success 2813 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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}\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
2 votes
Tags:
MathObservationBasic MathC++
Points:20
Tags:
Easy
Points:20
441 votes
Tags:
CombinatoricsMathematicsOpenApprovedEasy