Equally divide into two sets such that one set has maximum distinct elements | Javascript program to equally divide n elements into two sets such that second set has maximum distinct elements . ; Driver code
function distribution ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; var count = 1 ; for ( var i = 1 ; i < n ; i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) count ++ ; return Math . min ( count , parseInt ( n / 2 ) ) ; } var arr = [ 1 , 1 , 2 , 1 , 3 , 4 ] ; var n = arr . length ; document . write ( distribution ( arr , n ) ) ;