Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerEarth Monk and his Friends problem solution

YASH PAL, 31 July 2024
In this HackerEarth Monk and his Friends, problem-solution Monk is standing at the door of his classroom. There are currently N students in the class, the student got Ai candies.
There are still M more students to come. At every instant, a student enters the class and wishes to be seated with a student who has exactly the same number of candies. For each student, Monk shouts YES if such a student is found, NO otherwise.
HackerEarth Monk and his Friends problem solution

HackerEarth Monk and his Friends 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 ff first
#define ss second
#define pii pair<ll int,ll 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")


int main()
{
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
int t;
cin>>t;
while(t--)
{
int i,j,n,m;
cin>>n>>m;
assert(1<=n && n<=100000);
assert(1<=m && m<=100000);
vector<ll int>v(n+m);
rep(i,n+m){
cin>>v[i];
assert(0<= v[i] && v[i]<= 1000000000000);
}
set<ll int>mys;
rep(i,n)
mys.insert(v[i]);
for(i=n;i<n+m;i++)
{
if(mys.find(v[i])!=mys.end())
cout<<"YESn";
else
cout<<"NOn";
mys.insert(v[i]);
}
}
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 ff first
#define ss second
#define pii pair<ll int,ll 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")


int main()
{
ios_base::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
int i,j,n,m;
cin>>n>>m;
assert(1<=n && n<=100000);
assert(1<=m && m<=100000);
vector<ll int>v(n+m);
rep(i,n+m){
cin>>v[i];
assert(0<= v[i] && v[i]<= 1000000000000);
}
set<ll int>mys;
rep(i,n)
mys.insert(v[i]);
for(i=n;i<n+m;i++)
{
if(mys.find(v[i])!=mys.end())
cout<<"YESn";
else
cout<<"NOn";
mys.insert(v[i]);
}
}
return 0;
}
coding problems

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes