Solution to Str-Symmetry-Point by codility

28 Jul

Question: https://codility.com/demo/take-sample-test/str_symmetry_point

Question Name: Str-Symmetry-Point or StrSymmetryPoint

5 Replies to “Solution to Str-Symmetry-Point by codility

  1. I know that it’s a super easy problem but here’s my C++ solution:

    int solution(string &S) {
    
        if (S.length()%2 == 0) return -1; // even string size => no symmetry
        if (S.length() == 1) return 0; // string of size 1 => empty substrings
    
        // midpoint
        int m = S.length()/2;
    
        for(int i = 1; i <= m; i++) if(S[m-i] != S[m+i])  return -1;
    
        return m;
    }
    
    
    
  2. here’s my php solution 🙂

  3. a bit pythonic solution:

Leave a Reply

Your email address will not be published. Required fields are marked *