Sort by

recency

|

1331 Discussions

|

  • + 0 comments

    Here is my simple c++ solution, video explanation here : https://youtu.be/gcNAo9voHvk.

    string funnyString(string s) {
        string r = s;
        reverse(r.begin(), r.end());
        for(int i = 1; i < s.size(); i++){
            if(abs(s[i]-s[i-1]) != abs(r[i]- r[i-1])) return "Not Funny";
        }
        return "Funny";
    }
    
  • + 0 comments

    sunilllllllllllllll sirrrrrr, winner winner chicken dinner

  • + 0 comments

    Haskell

    module Main where
    
    import Control.Monad (replicateM_)
    import Data.Char (ord)
    
    cDif :: Char -> Char -> Int
    cDif x y = abs (ord x - ord y)
    
    sDif :: String -> [Int]
    sDif s = zipWith cDif s (tail s)
    
    solve :: String -> String
    solve s
        | sDif s == sDif (reverse s) = "Funny"
        | otherwise = "Not Funny"
    
    main :: IO ()
    main = do
        cases <- readLn :: IO Int
        replicateM_ cases $ do
            s <- getLine :: IO String
            putStrLn $ solve s
            
    
  • + 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";
    
  • + 0 comments
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    void strrev(char* str) {
        int len = strlen(str);
        int start = 0;
        int end = len - 1;
        while (start < end) {
            char temp = str[start];
            str[start] = str[end];
            str[end] = temp;
            start++;
            end--;
        }
    }
    
    char* funnyString(char* s) {
        int len = strlen(s);
        char rev_s[len+1];
        strcpy(rev_s, s);
        strrev(rev_s);
    
        int diff_s[len-1];
        int diff_rev_s[len-1];
    
        for (int i = 1; i < len; i++) {
            diff_s[i-1] = abs(s[i] - s[i-1]);
            diff_rev_s[i-1] = abs(rev_s[i] - rev_s[i-1]);
        }
    
        int funny = 1;
        for (int i = 0; i < len-1; i++) {
            if (diff_s[i] != diff_rev_s[i]) {
                funny = 0;
                break;
            }
        }
    
        if (funny) {
            return "Funny";
        } else {
            return "Not Funny";
        }
    }
    
    int main() {
        int t;
        scanf("%d", &t);
        while (t--) {
            char s[10001];
            scanf("%s", s);
            printf("%s\n", funnyString(s));
        }
        return 0;
    }