Function to find the length of the longest balanced substring
def longestSub ( s ) : NEW_LINE INDENT max_len = 0 NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i , n ) : NEW_LINE INDENT if ( isValid ( s [ i : j - i + 1 ] ) and max_len < j - i + 1 ) : NEW_LINE INDENT max_len = j - i + 1 NEW_LINE DEDENT DEDENT DEDENT return max_len NEW_LINE DEDENT