Longest substring with no pair of adjacent characters are adjacent English alphabets | Function to find the longest substring satisfying the given condition ; Stores all temporary substrings ; Stores the longest substring ; Stores the length of the subT ; Stores the first character of S ; Traverse the string ; If the absolute difference is 1 ; Update the length of subT ; Update the longest substring ; Otherwise , stores the current character ; Again checking for longest substring and update accordingly ; Print the longest substring ; Driver Code ; Given string ; Function call to find the longest substring satisfying given condition
def findSubstring ( S ) : NEW_LINE INDENT T = " " NEW_LINE ans = " " NEW_LINE l = 0 NEW_LINE T += S [ 0 ] NEW_LINE for i in range ( 1 , len ( S ) ) : NEW_LINE INDENT if ( abs ( ord ( S [ i ] ) - ord ( S [ i - 1 ] ) ) == 1 ) : NEW_LINE INDENT l = len ( T ) NEW_LINE if ( l > len ( ans ) ) : NEW_LINE INDENT ans = T NEW_LINE DEDENT T = " " NEW_LINE T += S [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT T += S [ i ] NEW_LINE DEDENT DEDENT l = len ( T ) NEW_LINE if ( l > len ( ans ) ) : NEW_LINE INDENT ans = T NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " aabdml " NEW_LINE findSubstring ( S ) NEW_LINE DEDENT