Longest sub | Function to return the length of the longest sub - array whose product of elements is 0 ; Driver code
function longestSubArray ( arr , n ) { var isZeroPresent = false ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) { isZeroPresent = true ; break ; } } if ( isZeroPresent ) return n ; return 0 ; } var arr = [ 1 , 2 , 3 , 0 , 1 , 2 , 0 ] ; var n = arr . length ; document . write ( longestSubArray ( arr , n ) ) ;