Skip to content
Programming101
Programmingoneonone

Learn everything about programming

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

Learn everything about programming

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

Topics we are covering

Toggle
  • HackerEarth Ali and Helping innocent people problem solution.
    • second 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
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes