Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth K – Jump problem solution

YASH PAL, 31 July 202414 February 2026
In this HackerEarth K – Jump problem solution we have 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.
 
 
HackerEarth K - Jump problem solution

 

 

HackerEarth K – Jump problem solution.

#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define MAX5 1000005
int arr[MAX5];
int n,k;
int dp[MAX5];
int n2(){
int ans = 0;
for(int i = 0; i < n; i++){
dp[i] = 1;
}
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
if(arr[i] >= arr[j] + k){
dp[i] = max(dp[i], 1 + dp[j]);
}
}
}
for(int i = 0; i < n; i++){
ans = max(ans, dp[i]);
}
return ans;
}

multiset <int> p;
multiset <int> :: iterator it;

int nlogn(){
p.clear();
for(int i=0;i<n;i++)
{
int tmp = arr[i];
it = p.upper_bound(tmp-k);
if(it == p.end())
{
p.insert(tmp);
continue;
}
if(*it > tmp)
{
p.erase(it);
p.insert(tmp);
}
}
return p.size();
}

int main()
{
cin >> k >> n;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
cout << nlogn() << endl;
}
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes