AlgoUniversity
  • Go Back
Discussion
Optum Q2 :

Author

Sumeet Kumar Mishra

Difficulty Level : Easy

Submissions : 81

Asked In :

Marks :10

: 1 | : 0

There are 2 boys in a class who have been given a target, $$$k$$$ by their class teacher. The students have an array of $$$n$$$ elements $$$a_i$$$. Their task to remove the minimum number of elements from this array such that the absolute difference between any two elements in the resulting array is lesser than or equal to k. Find the minimum number of elements that the boys need to remove from the array.

Constraints

  1. $$$1 \leq n \leq 100000$$$
  2. $$$1 \leq arr[i] \leq 100000$$$

Input

The first line of the input contains two integers $$$n$$$ and $$$k$$$ representing the length of the array and the maximum difference desired. The next line contains a sequence of n integers $$$a_i$$$

Output

Output a single integer which is the answer to the problem

Example

Input
3 3
5 10 2
Output
1

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.