As a beginner in programming, Mishki came to the HackerEarth platform, to become a better programmer. She solved some problems and felt very confident. Later being a fan of HackerEarth, she gave a problem to her friends to solve. They will be given a string containing only lower case characters (a-z), and they need to find that by using the characters of the given string, how many times they can print "hackerearth"(without quotes). As they are new to the programming world, please help them.
Example:
Input: n = 13, s = "aahkcreeatrha"
Output: 1
Approach
C++
#include <bits/stdc++.h>using namespace std;int printHackerearth(int n, string s){int f[26] = {0};for (int i = 0; i < n; i++)f[s[i] - 'a']++;int min1 = INT_MAX;min1 = min(min1, f[0] / 2);min1 = min(min1, f[2]);min1 = min(min1, f[4] / 2);min1 = min(min1, f[7] / 2);min1 = min(min1, f[10]);min1 = min(min1, f[17] / 2);min1 = min(min1, f[19]);return min1;}int main(){int n = 13;string s = "aahkcreeatrha";cout << printHackerearth(n, s) << "\n";return 0;}
No comments:
Post a Comment