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 Filling stones problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Filling stones problem solution You are given an integer N. You have total 2N stones numbered from 1 to 2N. You have initially two empty arrays of size N each. You have to fill both the arrays utilizing all the 2N stones and using each stone in only one array.
 
Let us define the beauty of an array as the difference between the sum of elements at odd positions and the sum of elements at even positions.
 
The beauty of an array is |s1 – s2| where:
 
S1 = Sigma(Ai1) where Ai1 are the elements positioned at an odd position in an array
S2 = Sigma(Ai2) where Ai2 are the elements positioned at an even position in an array 
Your task is to arrange the stones in both arrays such that the product of the beauty of both arrays is as minimum as possible.
 
 
HackerEarth Filling stones problem solution

 

 

HackerEarth Filling stones problem solution.

#include<bits/stdc++.h>
#include<climits>

using namespace std;

int main() {
cin.tie(0);
long long int n;
cin >> n;
long long int ans = 0;
if (n == 1) {
ans = 2;
}
else if (n == 2) {
ans = 1;
}
cout << ans << endl;
}
 
 
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