K - Jump
Practice
4.4 (22 votes)
Arrays
Data structures
Medium
One Dimensional
Standard template library
Problem
34% Success 11538 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$$
Explanation
1 3 5 7 10 - Length 5
Code Editor
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
37 votes
Tags:
1-D ArrayArraysData StructuresMediumString Manipulation
Points:30
28 votes
Tags:
Basic ProgrammingArraysImplementation1-DData Structures
Points:30
39 votes
Tags:
ArraysData StructuresData manipulation1-D
Editorial
Login to unlock the editorial
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
Results
Custom Input
Run your code to see the output