Skip to content
Programming101
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
Programming101
Programmingoneonone

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 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