Count number of trailing zeros in product of array | Returns count of zeros in product of array ; Count number of 2 s in each element ; Count number of 5 s in each element ; Return the minimum ; Driver code
function countZeros ( a , n ) { let count2 = 0 , count5 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { while ( a [ i ] % 2 == 0 ) { a [ i ] = parseInt ( a [ i ] / 2 ) ; count2 ++ ; } while ( a [ i ] % 5 == 0 ) { a [ i ] = parseInt ( a [ i ] / 5 ) ; count5 ++ ; } } return ( count2 < count5 ) ? count2 : count5 ; } let a = [ 10 , 100 , 20 , 30 , 50 , 90 , 12 , 80 ] ; let n = a . length ; document . write ( countZeros ( a , n ) ) ;