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.
publicstaticStringfunnyString(Strings){//use pointers for start and end of the string //iterate over each stringinti=1,j=s.length()-2;while(i<=j){//compare abs ascii diff between val adjacent ascending valsintleftAbs=Math.abs(s.charAt(i)-s.charAt(i-1));intrightAbs=Math.abs(s.charAt(j)-s.charAt(j+1));//if the diff arent the same, return Not Funnyif(leftAbs!=rightAbs)return"Not Funny";i++;j--;}//else return funnyreturn"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 →
My Java solution: