• + 0 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";