You are viewing a single comment's thread. Return to all comments →
Two pointer Solution in JavaScript
function funnyString(s) { let left = 0; let right = s.length - 1; while (left <= right) { let diffLeft = Math.abs(s[left].charCodeAt(0) - s[left + 1].charCodeAt(0)); let diffRight = Math.abs( s[right].charCodeAt(0) - s[right - 1].charCodeAt(0) ); if (diffLeft !== diffRight) { return "Not Funny"; } left++; right--; } return "Funny"; }
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 →
Two pointer Solution in JavaScript