Sort by

recency

|

1336 Discussions

|

  • + 0 comments
    def diff(arr):
        res=[]
        for i in range(len(arr)-1):
            res.append(abs(ord(arr[i])-ord(arr[i+1])))
        return res
    
    def funnyString(s):
        st=list(s)
        rev=st[::-1]
        res1=diff(st)
        res2=diff(rev)
        return 'Funny' if res1==res2 else 'Not Funny'
    

    or

    def funnyString(s):
        for i in range(1, len(s)//2+1):
            if abs(ord(s[i])-ord(s[i-1])) != abs(ord(s[-i])-ord(s[-i-1])):
                return 'Not Funny'
        return 'Funny'
    
  • + 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
    def funnyString(s):
        for i in range(1, math.ceil(len(s)/2)+1):
            if abs(ord(s[i])-ord(s[i-1])) != abs(ord(s[-i])-ord(s[-i-1])):
                return 'Not Funny'
        return 'Funny'
                
    
  • + 1 comment

    My Python code

    def funnyString(s): s2 = s[::-1]

    lst1 = [abs(ord(s[i]) - ord(s[i-1])) for i in range(1, len(s))]
    lst2 = [abs(ord(s2[i]) - ord(s2[i-1])) for i in range(1, len(s2))]
    
    if lst1 == lst2:
        return 'Funny'
    else:
        return 'Not Funny'
    
  • + 0 comments
    public static String funnyString(String s) {
        
            StringBuilder build = new StringBuilder(s);
            String revStr = build.reverse().toString();
            
            int n = s.length();
            char[] firstStr = s.toCharArray();
            char[] secondStr = revStr.toCharArray();
            
            for(int i=0; i<n-1; i++){
                
                int diff1 = Math.abs((int)firstStr[i] - (int)firstStr[i+1]);
                int diff2 = Math.abs((int)secondStr[i] - (int)secondStr[i+1]);
                
                if(diff1 != diff2){
                    return "Not Funny";
                }
                
            }
            return "Funny";
    
        }