Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
Programmingoneonone

Learn everything about programming

HackerEarth The chocolate rooms problem solution

YASH PAL, 31 July 2024
In this HackerEarth The chocolate rooms problem solution your task is to take some chocolates from N different rooms. Each room contains the Pi number of chocolates of the same or different brands. You are given an integer K.
Write a program to determine whether you can visit each room and find K different brands of chocolates.
HackerEarth The chocolate rooms problem solution

HackerEarth The chocolate rooms problem solution.

#include <iostream>
#include <map>
#include <string.h>

using namespace std;


int main()
{
int t;
scanf("%d", &t);
while(t--) {
int n, k;
string line = "";
scanf("%d%d", &n, &k);
map<string, bool> m;
string s;
int ans = 0;
for (int i = 0; i < n; i++) {
int p;
scanf("%d", &p);
while (p--) {
cin >> s;
if (m.find(s) == m.end()) {
ans++;
m[s]= 1;
}
}

}
if (ans >= k) printf("Yesn");
else printf("Non");
}
return 0;
}

Second solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#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")
ll pow_mod(ll a, ll b) {
ll res = 1;
while(b) {
if(b & 1)
res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
int main() {
int t;
si(t);
assert(t >= 1 && t <= 5);
while(t--) {
int n, k, p;
si(n); si(k);
assert(n >= 1 && n <= 100);
assert(k >= 1 && k <= 1000);
string str;
set<string> s;
bool poss = false;
for(int i = 0; i < n; ++i) {
si(p);
assert(p >= 1 && p <= 100);
for(int j = 0; j < p; ++j) {
cin >> str;
assert(str.length() >= 1 && str.length() <= 10);
s.insert(str);
}
}
if(s.size() >= k) {
poss = true;
}
if(poss) {
printf("Yesn");
} else {
printf("Non");
}
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes