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

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

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