Smallest element in an array that is repeated exactly ' k ' times . | finds the smallest number in arr [ ] that is repeated k times ; Sort the array ; Find the first element with exactly k occurrences . ; Driver code
< ? php function findDuplicate ( $ arr , $ n , $ k ) { sort ( $ arr ) ; $ i = 0 ; while ( $ i < $ n ) { $ j ; $ count = 1 ; for ( $ j = $ i + 1 ; $ j < $ n && $ arr [ $ j ] == $ arr [ $ i ] ; $ j ++ ) $ count ++ ; if ( $ count == $ k ) return $ arr [ $ i ] ; $ i = $ j ; } return -1 ; } $ arr = array ( 2 , 2 , 1 , 3 , 1 ) ; $ k = 2 ; $ n = sizeof ( $ arr ) ; echo ( findDuplicate ( $ arr , $ n , $ k ) ) ; ? >