Minimum swaps required to bring all elements less than or equal to k together

Given an array of integers A and an integer B, find and return the minimum number of swaps
required to bring all the numbers less than or equal to B together.

Note: It is possible to swap any two elements, not necessarily consecutive.



Input Format

The first argument given is the integer array A.
The second argument given is the integer B.

Output Format

Return the minimum number of swaps.

Constraints

1 <= length of the array <= 100000
-10^9 <= A[i], B <= 10^9 

For Example

Input 1:
    A = [1, 12, 10, 3, 14, 10, 5]
    B = 8
Output 1:
    2

Input 2:
    A = [5, 17, 100, 11]
    B = 20
Output 2:
    1
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Minimum swaps required to bring all elements less than or equal to k together on Interview Code Editor
Sign Up
to access hints and editorial solutions for Minimum swaps required to bring all elements less than or equal to k together

Discussion


Loading...
Click here to start solving coding interview questions