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
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth The chocolate rooms problem solution

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