Count binary strings of length same as given string after removal of substrings "01" and "00" that consists of at least one '1' | Function to count the strings consisting of at least 1 set bit ; Initialize count ; Iterate through string ; The answer is 2 ^ N - 1 ; Given string ; Function call
function countString ( S ) { var count = 0 ; for ( var it = 0 ; it < S . length ; it ++ ) { if ( S [ it ] == ' ' && count > 0 ) { count -- ; } else { count ++ ; } } document . write ( ( 1 << count ) - 1 ) ; } var S = " " ; countString ( S ) ;