K - Jump
Practice
4.4 (22 votes)
Arrays
Data structures
Medium
One Dimensional
Standard template library
Problem
34% Success 11536 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Given an array $$A$$ of size $$N$$, you can jump from an index $$i$$ to another index $$j$$ if $$A[j] - A[i]$$ >= $$K$$, for $$j$$ > $$i$$. Find the length of the longest sequence of jumps that can be possible in the array. You can start at any index.

Input Format:

First line contains an integer $$K$$.

Second line contains the integer $$N$$.

Third line contains $$N$$ space separated integers (The array $$A$$)

Output Format:

Print the required length.

Constrains:

$$1$$ ≤ $$N,A[i],K$$ ≤ $$10$$ $$6$$

 

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
39 votes
Tags:
ArraysData StructuresData manipulation1-D
Points:30
7 votes
Tags:
HashmapHashingCounting and ArrangementsData StructuresMathArrays1-D
Points:30
126 votes
Tags:
Data StructuresImplementationMediumOne-dimensionalSets