Length of the longest substring without repeating characters | Python3 program to find the length of the longest substring without repeating characters ; Result ; Note : Default values in visited are false ; If current character is visited Break the loop ; Else update the result if this window is larger , and mark current character as visited . ; Remove the first character of previous window ; Driver code
def longestUniqueSubsttr ( str ) : NEW_LINE INDENT n = len ( str ) NEW_LINE res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT visited = [ 0 ] * 256 NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT if ( visited [ ord ( str [ j ] ) ] == True ) : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT res = max ( res , j - i + 1 ) NEW_LINE visited [ ord ( str [ j ] ) ] = True NEW_LINE DEDENT DEDENT visited [ ord ( str [ i ] ) ] = False NEW_LINE DEDENT return res NEW_LINE DEDENT str = " geeksforgeeks " NEW_LINE print ( " The ▁ input ▁ is ▁ " , str ) NEW_LINE len = longestUniqueSubsttr ( str ) NEW_LINE print ( " The ▁ length ▁ of ▁ the ▁ longest ▁ " " non - repeating ▁ character ▁ substring ▁ is ▁ " , len ) NEW_LINE