Skip to content
Programmingoneonone
Programmingoneonone
  • 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

HackerEarth Ali and Helping innocent people problem solution

YASH PAL, 31 July 2024
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

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 just 7 dollars. Ask all your career-related questions 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
©2026 Programmingoneonone | WordPress Theme by SuperbThemes