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
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth ( Problem A ) Pikachu and the Game of Strings problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth (Problem A) Pikachu and the Game of Strings problem solution, Pikachu has recently learnt a new move s. He knows he can work hard and convert it into a stronger move t. Both the moves s and t contain the same number of letters.
 
In a single day, Pikachu can increase any letter of move s by one, that is, in a single day, he can convert letter A to B, C to D, M to N and so on. He can also convert letter Z to letter A. 
 
Pikachu just realized he also has a hidden ability. It can help him increase any letter of move s by 13, that is, in a single day, he can convert letter A to letter N, B into O, M into Z, O into B and so on.  
 
Now Pikachu wants to know the minimum number of days in which he can convert the move s into move t ?
 
 
HackerEarth ( Problem A ) Pikachu and the Game of Strings problem solution

 

 

HackerEarth ( Problem A ) Pikachu and the Game of Strings problem solution.

#include <bits/stdc++.h>

using namespace std;

int main(){
int n;
cin>>n;
string s,t;
cin>>s>>t;
int ans=0;
for(int i=0;i<n;i++){
ans+=min((t[i]-s[i]+26)%26,1+(t[i]-(s[i]+13)+52)%26);
}
cout<<ans<<endl;
}
 

Second solution

n = int(raw_input())
s = raw_input()
t = raw_input()
def f(g):
x = ord(g[0])
y = ord(g[1])
return min((y-x)%26, (y-(x+13)%26)%26 + 1)
print sum(map(f, zip(s,t)))
 
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