Longest Substring containing '1' | Function to find length of longest substring containing '1' ; Count the number of contiguous 1 's ; Driver Code
function maxlength ( s ) { let n = s . length , i , j ; let ans = 0 ; for ( i = 0 ; i <= n - 1 ; i ++ ) { if ( s [ i ] == ' ' ) { let count = 1 ; for ( j = i + 1 ; j <= n - 1 && s [ j ] == ' ' ; j ++ ) count ++ ; ans = Math . max ( ans , count ) ; } } return ans ; } let s = " " ; document . write ( maxlength ( s ) ) ;