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 Ali and Helping innocent people problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Ali and Helping innocent people problem solution Arpasland has been surrounded by attackers. A truck enters the city. The driver claims the load is food and medicine from Iranians. Ali is one of the soldiers in Arpasland. He doubts about the truck, maybe it’s from the siege. He knows that a tag is valid if the sum of every two consecutive digits of it is even and its letter is not a vowel. Determine if the tag of the truck is valid or not.
 
We consider the letters “A”,”E”,”I”,”O”,”U”,”Y” to be vowels for this problem.
 
 
hackerEarth Ali and Helping innocent people problem solution
 

HackerEarth Ali and Helping innocent people problem solution.

#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e5 + 17;
string s, vowel = "AEOUIY";
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> s;
bool ok = 1;
for(auto i : {0, 3, 4, 7})
ok &= (s[i] + s[i + 1]) % 2 == 0;
ok &= vowel.find(s[2]) == string::npos;
cout << (ok ? "valid" : "invalid") << 'n';
}
 

second solution

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >

const int maxn=(int)(1e5+5);
const ll mod=(ll)(1e9+7);
int a[maxn];

bool check(int pos,char ch)
{
if((pos>=0 && pos<=1) || (pos>=3 && pos<=5) || (pos>=7 && pos<=8))
{
return (ch>='0' && ch<='9');
}

if(pos==2)
{
return ch>='A' && ch<='Z';
}

if(pos==6)
{
return ch=='-';
}
}

bool vowel(char ch)
{

if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U' || ch=='Y')
{
return true;
}

return false;
}

int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);

string s;cin>>s;

bool ans=true;

for(int i=0;i<s.size();i++)
{
assert(check(i,s[i]));

if(i==2 && vowel(s[i]))
{
ans=false;
}

if(i>=1 && s[i]>='0' && s[i]<='9' && s[i-1]>='0' && s[i-1]<='9')
{
int curr=(s[i]-'0')+(s[i-1]-'0');

if(curr%2==1)
{
cout<<i<<endl;

ans=false;
}
}
}

cout<<(ans?"valid":"invalid")<<endl;

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