Number of elements that can be seen from right side | javascript program to find number of elements that can be seen from right side . ; Driver code
function numberOfElements ( height , n ) { var max_so_far = 0 ; var coun = 0 ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( height [ i ] > max_so_far ) { max_so_far = height [ i ] ; coun ++ ; } } return coun ; } var n = 6 ; var height = [ 4 , 8 , 2 , 0 , 0 , 5 ] ; document . write ( numberOfElements ( height , n ) ) ;