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
def findDuplicate ( arr , n , k ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE i = 0 NEW_LINE while ( i < n ) : NEW_LINE INDENT j , count = i + 1 , 1 NEW_LINE while ( j < n and arr [ j ] == arr [ i ] ) : NEW_LINE INDENT count += 1 NEW_LINE j += 1 NEW_LINE DEDENT if ( count == k ) : NEW_LINE INDENT return arr [ i ] NEW_LINE DEDENT i = j NEW_LINE DEDENT return - 1 NEW_LINE DEDENT arr = [ 2 , 2 , 1 , 3 , 1 ] ; NEW_LINE k = 2 NEW_LINE n = len ( arr ) NEW_LINE print findDuplicate ( arr , n , k ) NEW_LINE