You are viewing a single comment's thread. Return to all comments →
**Javascript two pointer solution, Simple and time complexity Big 0(n) **
const englishAlphabet = "abcdefghijklmnopqrstuvwxyz"; let leftIndex = 0; let rightIndex = originalStr.length - 1; while(leftIndex < rightIndex) { let leftDiff = Math.abs(englishAlphabet.indexOf(originalStr[leftIndex]) - englishAlphabet.indexOf(originalStr[leftIndex + 1])); let rightDiff = Math.abs(englishAlphabet.indexOf(originalStr[rightIndex]) - englishAlphabet.indexOf(originalStr[rightIndex - 1])); if(leftDiff !== rightDiff) { return "Not Funny"; } leftIndex++; rightIndex--; } 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 →
**Javascript two pointer solution, Simple and time complexity Big 0(n) **