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 Roy and Coding Contest problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Roy and Coding Contest problem solution, Roy is going to organize the Finals of Coding Contest in his college’s computer labs. According to the rules of the contest, problem statements will be available on each computer as a pdf file.
 
Now there is N number of computers and only one of them has the pdf file. Roy has collected M number of pen drives from his friends. Copying pdf from computer to pen drive or from pen drive to a computer takes exactly 1 minute. Roy has to copy pdf to all N computers in the minimum (optimal) time possible. You are to find this minimum time. Please see Sample Test Explanation for clarity.
 
 
HackerEarth Roy and Coding Contest problem solution

 

 

HackerEarth Roy and Coding Contest problem solution.

def roy_and_coding_contest():
for t in xrange(input()):
n,m = map(int,raw_input().split())
count = 1
res = 1
while count < m and count < n:
count *= 2
res += 1
if count > n:
count /= 2
res -= 1
#print count
tmp = n-count
res = res + tmp/m
if tmp%m != 0:
res += 1
if n == 1:
print '0'
else:
print res
roy_and_coding_contest()
 

Second solution

#include <iostream>
using namespace std;

int main()
{
int t; cin>>t;
while(t--)
{
int N,M; cin>>N>>M;
int T=0;
int Ph=0; int Pdh=M;
int Ch=1; int Cdh=N-1;
// Ph pendrive have, Pdh pendrive dont have, Ch computer have, Cdh computer dont have,
while(Pdh && Cdh)
{
// cCh temp Computer have, cPh temp Peddrive have
T++;
int cPh = Ph + min(Pdh,Ch);
int cCh = Ch + min(Cdh,Ph);
Pdh -= min(Pdh,Ch);
Cdh -= min(Cdh,Ph);
Ph=cPh;
Ch=cCh;
}
if(Cdh)
T += (1 + ((Cdh-1)/Ph));
cout<<T<<endl;
}
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