Traverse the string
for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT previous_index = lps [ i - 1 ] NEW_LINE while ( previous_index > 0 and s [ i ] != s [ previous_index ] ) : NEW_LINE INDENT previous_index = lps [ previous_index - 1 ] NEW_LINE DEDENT DEDENT