Equally divide into two sets such that one set has maximum distinct elements | C # program to equally divide n elements into two sets such that second set has maximum distinct elements . ; Driver code
using System ; class GFG { static int distribution ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) count ++ ; return Math . Min ( count , n / 2 ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 2 , 1 , 3 , 4 } ; int n = arr . Length ; Console . WriteLine ( distribution ( arr , n ) ) ; } }