import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int numTestCases = s.nextInt();
while (numTestCases > 0) {
String word = s.next();
System.out.println(getNumRotations(word));
--numTestCases;
}
s.close();
}
public static int getNumRotations(String word) {
char[] wordArr = word.toCharArray();
int count = 0;
int j = word.length() - 1;
for(int i = 0; i < wordArr.length / 2; i++, j--){
count += Math.abs((int)(wordArr[i] - wordArr[j]));
}
return count;
}
}
enterprise application development, architecture , business analysis and programming
Thursday, 17 November 2016
The Love-Letter Mystery - Algorithm Solution in JAVA 8
Labels:
hackerrank,
interviews,
java,
project euler
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment