Palindrome from all the substrings
There's a simple linear solution. 

You don't have to check all substrings. If an [l, r] substring is a palindrome and r - l &gt; 2, so is [l + 1, r - 1]. Thus, it's sufficient to check only substrings of length 2 and 3. 

One can do with a single pass over the input string:

for i in [0 .. s.length() - 2]:
     if s[i] == s[i + 1]:
         return true
     if i != 0 and s[i - 1] == s[i + 1]:
         return true
return false