Random Generator
Practice
2.9 (10 votes)
Algorithms
Binary search
Greedy algorithms
Medium
Open
Sorting
Problem
52% Success 1312 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Aparna recently created a random number generator and now she wants Harsh to check if it works fine. She gives Harsh an array containing N numbers generated from this random number generator of hers, and two integers K and P. If the given array contains more than or equal to K numbers in the range X-P to X+P (both inclusive) for any integer X, then the random generator fails.

If for any X the generator fails then ultimately it fails.

Help Harsh in determining whether the random generator works well or not.

Input:
The first line contains T indicating the number of test cases.
Second line contains 3 space separated integers N, K and P.
The next line contains N integers generated by the random number generator.

Output:
For each Test Case Print 'YES' if random generator works correctly else print 'NO'. (Quotes for clarity)

Constraints:
1<=T<=10
1<=N<=10^5
1<=K<=N
|Element of array|<=10^9
0<=P<=10^9

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:30
8 votes
Tags:
AlgorithmsApprovedBinary SearchMediumOpenSorting
Points:30
7 votes
Tags:
AlgorithmsBinary search treeBinary SearchTrie
Points:30
18 votes
Tags:
AlgorithmsBinary SearchMediumPrefix sumSearchingTwo pointerprefix-sum