Minimum number of Bottles visible when a bottle can be enclosed inside another Bottle | Javascript code for the above approach ; Driver code ; Find the solution
function min_visible_bottles ( arr , n ) { let m = new Map ( ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( m . has ( arr [ i ] ) ) { m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) } else { m . set ( arr [ i ] , 1 ) } ans = Math . max ( ans , m . get ( arr [ i ] ) ) ; } document . write ( " " + " " + ans + " " ) ; } let n = 8 ; let arr = [ 1 , 1 , 2 , 3 , 4 , 5 , 5 , 4 ] ; min_visible_bottles ( arr , n ) ;