Put all obtained palindromes in a hash map to find only distinct palindrome
m [ s [ 0 ] ] = 1 NEW_LINE for i in xrange ( 1 , n ) : NEW_LINE INDENT for j in xrange ( 2 ) : NEW_LINE INDENT for rp in xrange ( R [ j ] [ i ] , 0 , - 1 ) : NEW_LINE INDENT m [ s [ i - rp - 1 : i - rp - 1 + 2 * rp + j ] ] = 1 NEW_LINE DEDENT DEDENT m [ s [ i ] ] = 1 NEW_LINE DEDENT