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 Aniruddhas Queue problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Aniruddha’s Queue problem solution Aniruddha is given a milestone M to reach in terms of distance. He is living in a different Galaxy where there are N days in a year. On an ith day, he can walk almost X distance. Assuming he walks optimally you need to output the minimum day number on which he will reach the milestone.
 
 
HackerEarth Aniruddha's Queue problem solution

 

 

HackerEarth Aniruddha’s Queue problem solution.

#include<iostream>
#include<map>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<functional>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<deque>
using namespace std;
long long arr[100010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,noOfDays;
scanf("%d",&noOfDays);
for(i=0;i<noOfDays;i++)
{
scanf("%lld",&arr[i]);
}
unsigned long long sum,ans=0;
scanf("%llu",&sum);
bool flag=false;
for(i=0;i<noOfDays;i++)
{
ans+=arr[i];
if(ans>=sum)
{
flag=true;
break;
}
}
if(flag)
{
printf("%dn",i+1);
}
else
{
sum=sum%ans;
ans=0;
for(i=0;i<noOfDays;i++)
{
ans+=arr[i];
if(ans>=sum)
{
flag=true;
break;
}
}
if(sum!=0)
printf("%dn",i+1);
else
{
ans=0;
for(i=0;i<noOfDays;i++)
{
if(arr[i]>0)
{
ans=i;
}
}
printf("%dn",ans+1);
}
//cout<<i+1<<endl;
}
}
return(0);
}
 
 

Second solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
ll ar[n],cnt=0;
for(int i=0;i<n;++i)
{
scanf("%lld",&ar[i]);
cnt+=ar[i];
}
ll m;
scanf("%lld",&m);
m%=cnt;
int ans;
if(m==0)
{
for(int i=n-1;i>=0;--i)
{
if(ar[i]!=0)
{
ans=i;
break;
}
}
}
else
{
for(int i=0;i<n;++i)
{
m-=ar[i];
if(m<=0)
{
ans=i;
break;
}
}
}
printf("%dn",ans+1);
}
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