Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • 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
Programming101

Learn everything about programming

HackerEarth Distinct Count problem solution

YASH PAL, 31 July 2024
In this HackerEarth Distinct Count problem solution we have given an array A of N integers, classify it as being Good Bad, or Average. It is called Good, if it contains exactly X distinct integers, Bad if it contains less than X distinct integers, and Average if it contains more than X distinct integers.
HackerEarth Distinct Count problem solution

HackerEarth Distinct Count problem solution.

#include <bits/stdc++.h>
using namespace std;
int main () {
int tc;
scanf("%d",&tc);
while (tc--) {
int n, k;
scanf("%d%d",&n,&k);
set < int > s;
int temp;
for (int i=0; i<n; i++) {
scanf("%d",&temp);
s.insert(temp);
}

if (s.size()<k) {
printf("Bad husbandn");
}
if (s.size()==k) {
printf("Perfect husbandn");
}
if (s.size()>k) {
printf("Lame husbandn");
}
}
return 0;
}

Second solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pb(v, a) v.push_back(a)
#define mp(a, b) make_pair(a, b)
#define MOD 1000000007
#define rep(i, a, b) for(i=a; i<=b; ++i)
#define rrep(i, a, b) for(i=a; i>=b; --i)
#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;
}
set<int> s;
int main()
{
int t, i, n, x, j, tmp;
si(t);
assert(t >= 1 && t <= 50);
rep(i, 1, t)
{
s.clear();
si(n);
si(x);
assert(n >= 1 && n <= 13000);
assert(x >= 1 && x <= 13000);
rep(j, 1, n)
{
si(tmp);
assert(tmp >= 1 && tmp <= 1000000000);
s.insert(tmp);
}
if(s.size() < x)
printf("Bad husbandn");
else if(s.size() > x)
printf("Lame husbandn");
else
printf("Perfect husbandn");
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
How to download udemy paid courses for free

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
©2025 Programming101 | WordPress Theme by SuperbThemes