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

HackerEarth Deleting Numbers problem solution

YASH PAL, 31 July 202411 February 2026
In this HackerEarth Deleting Numbers problem solution, Zenyk recently got an array with his n school grades a1,a2,…,an. He isn’t very happy with them and knows that his parents also will not be happy with his grades. But he also knows that his parents evaluate his performance in a very strange way. They care only about the middle element in the array of grades Zenyk got. More formally if Zenyk’s array is b and it has m elements, b[(m+1)/2] is Zenyk’s performance. Zenyk doesn’t want to disappoint his parents, so he wants to erase exactly k(k < n) grades from his array a in order to maximize his score.
HackerEarth Deleting Numbers problem solution

HackerEarth Deleting Numbers problem solution.

#include <bits/stdc++.h>
using namespace std;
int n , k;
int a[100005];
int main()
{
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
int l = (n + 1) / 2 , r = (n + 1) / 2;
bool odd = n % 2;
for(int i = 1; i <= k; i++)
{
int par = (i % 2) ^ odd;
if(par)
r++;
else
l--;
}
int maxNumber = 0;
for(int i = l; i <= r; i++)
maxNumber = max(maxNumber , a[i]);
cout << maxNumber;
}

Second solution

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 14;
int n, k;
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
int ans = 0;
for(int i = 0; i < n; i++){
int x;
cin >> x;
if(i >= (n - k - 1) / 2 && i <= n - (n - k) / 2 - 1)
ans = max(ans, x);
}
cout << ans << 'n';
}
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 *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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