Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • 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
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

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