• + 0 comments

    My Java solution:

    public static String funnyString(String s) {
            //use pointers for start and end of the string 
            //iterate over each string
            int i = 1, j = s.length() - 2;
            while(i <= j){
                //compare abs ascii diff between val adjacent ascending vals
                int leftAbs = Math.abs(s.charAt(i) - s.charAt(i - 1));
                int rightAbs = Math.abs(s.charAt(j) - s.charAt(j + 1));
                //if the diff arent the same, return Not Funny
                if(leftAbs != rightAbs) return "Not Funny";
                i++;
                j--;
            }
            //else return funny
            return "Funny";
        }