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
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Easy Going (Very Easy) problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Easy Going(Very Easy) problem solution Coders here is a simple task for you, you have given an array of size N and an integer M.
 
Your task is to calculate the difference between the maximum sum and minimum sum of N-M elements of the given array.
 
 
HackerEarth Easy Going.(Very Easy) problem solution

 

 

HackerEarth Easy Going.(Very Easy) problem solution.

#include <iostream>

using namespace std;

void input (int arr[], int n) {

for (int i = 0; i < n; i++)

cin >> arr[i];

}
void sort (int a[], int s) {

for (int i = 0; i < s - 1; i++) {

for (int j = 0; j < s - i - 1; j++) {

if (a[j] > a[j + 1]) {

int temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

}

}

}

}




int main()

{

int n, m, t, arr[1000];

cin >> t;



for (int i = 0; i < t; i++) {

cin >> n >> m;

input (arr, n);

sort (arr, n);

int max = 0, min = 0, k = n - m;

for (int j = 0; j < k; j++){

max += arr[n - j - 1];

min += arr[j];

}

cout << max - min << endl;

}

return 0;

}
 
 
 
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