Equally divide into two sets such that one set has maximum distinct elements | PHP program to equally divide n elements into two sets such that second set has maximum distinct elements . ; Driver code
< ? php function distribution ( $ arr , $ n ) { sort ( $ arr ) ; $ count = 1 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ arr [ $ i ] > $ arr [ $ i - 1 ] ) $ count ++ ; return min ( $ count , $ n / 2 ) ; } $ arr = array ( 1 , 1 , 2 , 1 , 3 , 4 ) ; $ n = count ( $ arr ) ; echo ( distribution ( $ arr , $ n ) ) ; ? >