Minimum number of subsets with distinct elements | Function to count subsets such that all subsets have distinct elements . ; Take input and initialize res = 0 ; Sort the array ; Traverse the input array and find maximum frequency ; For each number find its repetition / frequency ; Update res ; Driver code
< ? php function subset ( $ ar , $ n ) { $ res = 0 ; sort ( $ ar ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ count = 1 ; for ( ; $ i < $ n - 1 ; $ i ++ ) { if ( $ ar [ $ i ] == $ ar [ $ i + 1 ] ) $ count ++ ; else break ; } $ res = max ( $ res , $ count ) ; } return $ res ; } $ arr = array ( 5 , 6 , 9 , 3 , 4 , 3 , 4 ) ; $ n = sizeof ( $ arr ) ; echo subset ( $ arr , $ n ) ; ? >