Longest Substring of 1 's after removing one character | Function to calculate the length of the longest substring of '1' s that can be obtained by deleting one character ; Initializing i and j as left and right boundaries of sliding window ; If current character is '0' ; Decrement k by one ; If k is less than zero and character at ith index is '0' ; Return result ; Driver Code
function longestSubarray ( s ) { var i = 0 , j = 0 , k = 1 ; for ( j = 0 ; j < s . length ; ++ j ) { if ( s [ j ] == ' ' ) k -- ; if ( k < 0 && s [ i ++ ] == ' ' ) k ++ ; } return j - i - 1 ; } var S = " " ; document . write ( longestSubarray ( S ) ) ;