Maximum number of splits of a binary number | Function to return the required count ; If the splitting is not possible ; To store the final ans ; Counting the number of zeros ; Return the final answer ; Driver code
function cntSplits ( s ) { if ( s [ s . length - 1 ] == ' ' ) return - 1 ; var ans = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) ans += ( s [ i ] == ' ' ) ; return ans ; } var s = " " ; document . write ( cntSplits ( s ) ) ;