text: k | Returns k - th distinct element in arr . ; Check if current element is present somewhere else . ; If element is unique ; Driver Code
code: < ? php function printKDistinct ( $ arr , $ n , $ k ) { $ dist_count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ j ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) if ( $ i != $ j && $ arr [ $ j ] == $ arr [ $ i ] ) break ; if ( $ j == $ n ) $ dist_count ++ ; if ( $ dist_count == $ k ) return $ arr [ $ i ] ; } return -1 ; } $ ar = array ( 1 , 2 , 1 , 3 , 4 , 2 ) ; $ n = sizeof ( $ ar ) / sizeof ( $ ar [ 0 ] ) ; $ k = 2 ; echo printKDistinct ( $ ar , $ n , $ k ) ; ? >