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
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Gotta catch ’em all! problem solution

YASH PAL, 31 July 2024
In this HackerEarth Gotta catch ’em all! problem solution Little Arihant has always wanted to be the best Pokemon trainer in this world. And he thinks he has achieved his goal, so he wants to quickly go and meet Professor Oak and verify this fact. But like all Pokemon trainers, he has a weird habit, too. He catches Pokemons which can go through evolution to become a better one. After roaming in the Pokeworld for days, he has finally managed to catch k such Pokemons.
The way he can make a Pokemon go through evolution is NOT by making them fight battles, but by using an evolution stone. Since he has k Pokemons, he naturally needs k evolution stones for every one of them, as well.
Now it takes little Arihant one complete day, to use the evolution stone on one Pokemon. And for each Pokemon, he knows how many days will they take to evolute after the evolution stone has been used on them.
He will go to meet Professor Oak, the very next day, once all his Pokemons have gone through evolution. He can select the order of applying evolution stones as he likes, so he wants to do it in such a way that he gets to meet Professor Oak as soon as possible!
HackerEarth Gotta catch 'em all! problem solution

HackerEarth Gotta catch ’em all! problem solution.

#include <bits/stdc++.h>
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0);cout.tie(0); } } _;

#define lct long long int t;cin>>t;while(t--)
#define llin(a) ll a; cin>>a;
#define rep(i,n) for(ll i=0;i<n;i++)

typedef long long int ll;

int main()
{
llin(n);
ll arr[n];
rep(i,n)
cin>>arr[i];

sort(arr,arr+n);

ll cnt=1,buf=arr[n-1];
for(ll i=n-2;i>=0;i--)
{
if(arr[i]<buf)
{
buf--;
cnt++;
}
else
{
cnt++;
buf=arr[i];
}
}
cnt+=buf;
cout<<++cnt<<endl;

}

Second solution

from sys import *

n = int(stdin.readline())
a = map(int, stdin.readline().split())
#print a
a = sorted(a, reverse = True)
#print a

print max(i + a[i] + 2 for i in range(n))
coding problems solutions

Post navigation

Previous post
Next post

Related website

The Computer Science

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