Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • 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
Programming101
Programmingoneonone

Learn everything about programming

HackerEarth Median Game problem solution

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

Topics we are covering

Toggle
  • HackerEarth Median Game problem solution.
    • Second 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

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

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