Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • 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
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Deleting Numbers problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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