Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Harry and String problem solution

YASH PAL, 31 July 202417 February 2026
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 HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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