Remove all 1 s from the adjacent left of 0 s in a Binary Array | Function to find the maximum number of 1 's before 0 ; Traverse the array ; If value is 1 ; If consecutive 1 followed by 0 , then update the maxCnt ; Print the maximum consecutive 1 's  followed by 0 ; Driver Code ; Function Call ; Function Call
function noOfMoves ( arr , n ) { let cnt = 0 ; let maxCnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) { cnt ++ ; } else { if ( cnt != 0 ) { maxCnt = Math . max ( maxCnt , cnt ) ; cnt = 0 ; } } } document . write ( maxCnt + " " ) ; } let arr = [ 0 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 ] ; let N = arr . length ; noOfMoves ( arr , N ) ; let arr1 = [ 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 ] ; N = arr . length ; noOfMoves ( arr1 , N ) ;