Replace ' ? ' to convert given string to a binary string with maximum count of '0' and "10" | Function to maximize count of 0 and 10 by replacing character ' ? ' to '0' or '1' ; Traverse the given string ; If current character is ' ? ' ; Replace str [ i ] to '0' ; Given string
function findMaxOccurence ( str , N ) { for ( var i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ' ) { str [ i ] = ' ' ; } } document . write ( str . join ( ' ' ) ) ; } var str = " " . split ( ' ' ) ; var N = str . length ; findMaxOccurence ( str , N ) ;