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 Monk and his Friends problem solution

YASH PAL, 31 July 202414 February 2026
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 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