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