Length of the longest substring without repeating characters | JavaScript 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
function longestUniqueSubsttr ( str ) { var n = str . length ( ) ; var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var visited = new [ 256 ] ; for ( var j = i ; j < n ; j ++ ) { if ( visited [ str . charAt ( j ) ] == true ) break ; else { res = Math . max ( res , j - i + 1 ) ; visited [ str . charAt ( j ) ] = true ; } } visited [ str . charAt ( i ) ] = false ; } return res ; } var str = " " ; document . write ( " " + str ) ; var len = longestUniqueSubsttr ( str ) ; document . write ( " " + " " + " " + len ) ;