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 Will Rick survive or not problem solution

YASH PAL, 31 July 2024
In this HackerEarth Will Rick survive or not problem solution After Governor’s attack on the prison, Rick found himself surrounded by walkers. They are coming towards him from all sides. Now, suppose Rick has an infinite number of bullets with him. Suppose Rick needs 1 bullet to kill each walker (yeah he is good at killing walkers. They need to be shot at the head. See, how good he is). Now as soon as he kills 1 walker rest of the walkers move forward by 1 m. There are n walkers each at some distance from Rick. If any walker is able to reach Rick, he dies. Now, you need to tell if he survives or not. If he survives print “Rick now go and save Carl and Judas” else print “Goodbye Rick” followed by no. of walkers he was able to kill before he died in next line. One more thing Rick’s gun can fire 6 shots without reloading. It takes him 1 sec to reload and during this time walkers move 1 m forward.
HackerEarth Will Rick survive or not problem solution

HackerEarth Will Rick survive or not problem solution.

#include<bits/stdc++.h>
using namespace std;
int ar[50005];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(ar,0,sizeof(ar));
int n,tmp;
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",&tmp);
ar[tmp]++;
}
int ans=0,cnt=0,j=0;
bool pos=true;
for(int i=1;i<=n;++i)
{
while(ar[j]==0)
j++;
ar[j]--;
if(j-cnt<=0)
{
pos=false;
break;
}
if(i%6==0 && i!=0)
cnt++;
cnt++;
ans++;
}
if(pos)
printf("Rick now go and save Carl and Judasn");
else
printf("Goodbye Rickn%dn",ans);
}
return 0;
}

Second solution

#include<bits/stdc++.h>
#define LET(x,a) __typeof(a) x(a)
#define TR(v,it) for( LET(it,v.begin()) ; it != v.end() ; it++)
#define FORi(i,a,b) for(LET(i,a) ; i<b; i++)
#define repi(i,n) FORi(i,(__typeof(n))0,n)
#define FOR(i,a,b) for(i=a ; i<b; i++)
#define rep(i,n) FOR(i,0,n)
#define si(n) scanf("%d",&n)
#define DRT() int t; cin>>t; while(t--)
#define DRI(n) int n; cin>>n;
#define DRII(n,m) int n,m; cin>>n>>m;

using namespace std;

int A[50001];
int main()
{
DRT()
{
memset(A,0,sizeof(A));
int x;
DRI(n); repi(i,n){si(x);A[x]++;}
int c=0;
int i;
x=0;
assert(n<=100000);
rep(i,n)
{
while(A[x]==0)x++;
A[x]--;
if(c>= x)break;
c++;
if(i%6==5)c++;
}
if(i==n)
cout<<"Rick now go and save Carl and Judasn";
else
{
cout<<"Goodbye Rickn"<<i<<endl;
}
}

return 0;
}
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