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 The Enlightened Ones problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth The Enlightened Ones problem solution There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directions. Since, they do not want to waste their efficiency on trivial things of the world, they want to keep their range minimum.
 
Also, when we say that the N temples are in a straight line, we mean that that all the temples lie on something like an X-axis in a graph.
 
Find the minimum enlightenment value such that all the temples can receive it.
 
 
HackerEarth The Enlightened Ones problem solution

 

 

HackerEarth The Enlightened One’s problem solution.

#include<bits/stdc++.h>


using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define elif else if
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define CLEAR(array, value) memset(ptr, value, sizeof(array));
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define pi(a) printf("%d", a)
#define pl(a) printf("%lld", a)
#define pn printf("n")
#define SZ(x) (int)((x).size())

vector< int>tmp;
int check(int num,int k)
{
int i,j,prev=tmp[0]+num;
k--;
for(i=1;i<tmp.size();i++)
{
if(prev+num>=tmp[i])
continue;
if(k==0)
return 0;
prev=tmp[i]+num;
k--;
}
return 1;
}
int main()
{
int n,i,j,k;
cin>>n>>k;
tmp.resize(n);
rep(i,n)
cin>>tmp[i];
sort(tmp.begin(),tmp.end());

int l=0,h=0,mid,p=-1;
h=100000000;
while(h>=l)
{
mid=(l+h)/2;
int vv=check(mid,k);
// cout<<l<<" "<<h<<" "<<mid<<" "<<vv<<"n";
if( check(mid,k) && check(mid-1,k)==0)break;
if(vv==0)
{
p=mid;
l=mid+1;
}
else
h=mid-1;
}
cout<<mid<<"n";
return 0;
}
 

Second solution

#include<bits/stdc++.h>


using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define elif else if
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define CLEAR(array, value) memset(ptr, value, sizeof(array));
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define pi(a) printf("%d", a)
#define pl(a) printf("%lld", a)
#define pn printf("n")
#define SZ(x) (int)((x).size())

vector< int>tmp;
int check(int num,int k)
{
int i,j,prev=tmp[0]+num;
k--;
for(i=1;i<tmp.size();i++)
{
if(prev+num>=tmp[i])
continue;
if(k==0)
return 0;
prev=tmp[i]+num;
k--;
}
return 1;
}
int main()
{
int n,i,j,k;
cin>>n>>k;
tmp.resize(n);
rep(i,n)
cin>>tmp[i];
sort(tmp.begin(),tmp.end());

int l=0,h=0,mid,p=-1;
h=100000000;
while(h>=l)
{
mid=(l+h)/2;
int vv=check(mid,k);
// cout<<l<<" "<<h<<" "<<mid<<" "<<vv<<"n";
if( check(mid,k) && check(mid-1,k)==0)break;
if(vv==0)
{
p=mid;
l=mid+1;
}
else
h=mid-1;
}
cout<<mid<<"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 *

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