Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
Programmingoneonone

Learn everything about programming

HackerEarth Harry and String problem solution

YASH PAL, 31 July 2024
In this HackerEarth Harry and String problem solution Harry was studying a magic book that categorizes the magic spells into 3 categories – Good , Worst and Bad. If any spell contains all the vowels in alphabetical order then that spell is categorized as Good. If it contains the vowels in reverse alphabetical order , then that spell is categorized as Worst. All the other spells that do not fall in any of the categories before are categorized as Bad. 
Now Harry tries to evaluate himslef by solving a spell categorization exercise at the end of the book , but since he is confused can you help him by solving the problems.
HackerEarth Harry and String problem solution

HackerEarth Harry and String problem solution.

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;

#define pb push_back

const ll INF=1e18;

const int mod=1000000007;

char str[100009];

int main()
{
ll t,n,m,i,j,k;
scanf ("%lld",&t);
while (t--)
{
scanf ("%s",str);

ll st[5],ed[5],f=0;

for (i=0;i<5;++i)
{
st[i]=-1;
ed[i]=-1;
}

for (i=0;str[i]!='';++i)
{
if (str[i]=='a')
{
if (st[0]==-1)
st[0]=i;
ed[0]=i;
}
else if (str[i]=='e')
{
if (st[1]==-1)
st[1]=i;
ed[1]=i;
}
else if (str[i]=='i')
{
if (st[2]==-1)
st[2]=i;
ed[2]=i;
}
else if (str[i]=='o')
{
if (st[3]==-1)
st[3]=i;
ed[3]=i;
}
else if (str[i]=='u')
{
if (st[4]==-1)
st[4]=i;
ed[4]=i;
}
}
k=ed[0];
for (i=1;i<5;++i)
{
if (st[i]!=-1)
{
if (k<st[i])
k=ed[i];
else
f=1;
}
}
if (f==1)
{
k=ed[4];
for (i=3;i>=0;--i)
{
if (st[i]!=-1)
{
if (k<st[i])
k=ed[i];
else
f=2;
}
}
}
if (f==0)
puts ("Good");
else if (f==1)
puts ("Worst");
else
puts ("Bad");
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes