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
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Help Fredo problem solution

YASH PAL, 31 July 202411 February 2026
In this HackerEarth Help, Fredo problem solution Fredo is assigned a task today. He is given an array A containing N integers. His task is to update all elements of array to some minimum value x, that is, A[i] = x; 1 <= i <= N  such that product of all elements of this new array is strictly greater than the product of all elements of the initial array. Note that x should be as minimum as possible such that it meets the given condition. Help him find the value of x.
HackerEarth Help Fredo problem solution

HackerEarth Help Fredo with problem solution.

#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ll a[100005];
int n;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
assert(a[i]>=1 && a[i]<=1e10);
}
sort(a,a+n);
ld val=0;
for (int i=0;i<n;i++)
val+= (ld)(log((ld)(a[i])));
ll left=a[0],right=a[n-1]+1,ans;
while(left<=right)
{
ll mid=(left+right)/2;
ld temp= (ld)n * (ld)(log((ld)(mid)));
if(val < temp)
{
ans=mid;
right=mid-1;
}
else
left=mid+1;
}
cout<<ans<<"n";
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 *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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