You are viewing a single comment's thread. Return to all comments →
TypeScript O(n) time and O(1) space solution:
function funnyString(s: string): string { let i = 1 let j = s.length - 2 while (i < s.length && j > -1) { let leftVal = Math.abs(s[i -1].charCodeAt(0) - s[i].charCodeAt(0)) let rightVal = Math.abs(s[j].charCodeAt(0) - s[j + 1].charCodeAt(0)) if (leftVal !== rightVal) { return "Not Funny" } i++ j-- } 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 →
TypeScript O(n) time and O(1) space solution: