We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
it might be happening because you are not taking the absolute value;
if you don't do so then "acxz" is funny and "aczx" is not funny;
here is my code...
import java.util.Scanner;
public class FunnyString {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
for(int a0 = 0; a0 < q; a0++){
String s = in.next();
String result = funnyString(s);
System.out.println(result);
}
in.close();
}
private static String funnyString(String s) {
for(int i=1;i<=s.length()/2;++i){
int diff1=0,diff2=0;
diff1=s.charAt(i)-s.charAt(i-1);
if(diff1<0)
diff1*=-1;
diff2=s.charAt(s.length()-i)-s.charAt(s.length()-1-i);
if(diff2<0)
diff2*=-1;
if(diff1!=diff2){
return "Not Funny";
}
}
return "Funny";
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Funny String
You are viewing a single comment's thread. Return to all comments →
it might be happening because you are not taking the absolute value; if you don't do so then "acxz" is funny and "aczx" is not funny; here is my code... import java.util.Scanner;
public class FunnyString {
}