All Tracks Algorithms Greedy Algorithms Basics of Greedy Algorithms Problem

( Problem A ) Pikachu and the Game of Strings
Tag(s):

Algorithms, Basics of Greedy Algorithms, Greedy Algorithms, Very-Easy

Problem
Editorial
Analytics

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 $$  ?
 

Constraints:

  • \(1\le |s|=|t|\le 10^5\)
  • s and consists of uppercase English letters only

Input format:

  • First line contains an integer $$ n $$, the length of strings $$ s $$ and $$ t $$
  • Second line contains string $$ s $$ of length $$ n $$
  • Third line contains string $$ t $$ of length $$ n $$ 

Output format:

  • Output single line containing the minimum number of days required
SAMPLE INPUT
4
ABCT
PBDI
SAMPLE OUTPUT
7
Explanation

Pikachu can convert move s into t in 7 days as follows:

  1. $$ A -> N $$ (1st letter)
  2.  $$ N -> O $$ (1st letter)
  3.  $$ O -> P $$ (1st letter)
  4. $$ C -> D $$ (3rd letter)
  5. $$ T -> G $$ (4th letter)
  6. $$ G -> H $$ (4th letter)
  7. $$ H -> I $$ (4th letter)
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

August Easy '18

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?