You are viewing a single comment's thread. Return to all comments →
https://codepair.hackerrank.com/paper/WV5eMmhM?b=eyJyb2xlIjoiY2FuZGlkYXRlIiwibmFtZSI6InJhdmlyb3NoYW4iLCJlbWFpbCI6InJhdmlyb3NoYW4udGFsa0BnbWFpbC5jb20ifQ%3D%3D
public class Solution { public static void main(String[] args) {
// System.out.println("Starting the program"); try { BufferedReader br = new BufferedReader(new InputStreamReader( System.in)); String input; input=br.readLine(); int T=Integer.parseInt(input); String[] inputArray = new String[T]; for (int i = 0; i < T; i++) { inputArray[i]=br.readLine(); } //System.out.println("=========================="); for (String string : inputArray) { int size=string.length(); int counter=0; int i,j; for (i = 0, j=size-1; i+1 <j-1; i++,j--) { if(string.charAt(i)==string.charAt(i+1)){ counter++; } if(string.charAt(j)==string.charAt(j-1)){ counter++; } } if(size%2==0){ if(string.charAt(i)==string.charAt(j)){ counter++; } } else{ if(string.charAt(i)==string.charAt(i+1)){ counter++; } if(string.charAt(i+1)==string.charAt(j)){ counter++; } } System.out.println(counter); } } catch (Exception io) { io.printStackTrace(); } // System.out.println("Ending the program"); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Alternating Characters
You are viewing a single comment's thread. Return to all comments →
https://codepair.hackerrank.com/paper/WV5eMmhM?b=eyJyb2xlIjoiY2FuZGlkYXRlIiwibmFtZSI6InJhdmlyb3NoYW4iLCJlbWFpbCI6InJhdmlyb3NoYW4udGFsa0BnbWFpbC5jb20ifQ%3D%3D
public class Solution { public static void main(String[] args) {
}