Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • 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

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

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes