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 Median Game problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Median Game problem solution, You are given an array A of N integers. You perform this operation N – 2 times: For each contiguous subarray of odd size greater than 2, you find the median of each subarray(Say medians obtained in a move are m1,m2,m3,..,mk).
 
In each move, you remove the first occurrence of value min(m1,m2,m3,…,mk) from the original array. After removing the element the array size reduces by 1 and no void spaces are left. For example, if we remove element 2 from the array {1,2,3,4}, the new array will be {1,3,4}.
 
Print a single integer denoting the sum of numbers that are left in the array after performing the operations. You need to do this for T test cases.
 
 
HackerEarth Median Game problem solution

 

 

HackerEarth Median Game problem solution.

#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);

int n, t;

int main() {
IOS;
cin>>t;
while(t--){
cin>>n;
int mn = INT_MAX, mx = -1;
for(int i = 0; i < n; i++){
int u;
cin>>u;
mx = max(mx, u);
mn = min(mn, u);
}
cout<<mx + mn<<"n";
}
return 0;
}
 

Second solution

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int mn = INT_MAX, mx = -mn;
while(n--){
int x;
cin >> x;
mn = min(mn, x);
mx = max(mx, x);
}
cout << mn + mx << '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 *

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