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

HackerEarth Filling stones problem solution

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

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes