Assuming that : all numbers of the array range from [0,n-1] <n being the
size of the array>

Copy array A to B

Make all integers negative

Scan the array while B[B[i]] = B[B[i]] + n

Now scan the array for the smallest non-negative element : element of
original array having the index of the smallest element is the element that
exactly appears k times in the array

Eg:
Assume k=3 and m=5

1 2 3 1 2 3 1 2 3 1 3 1 3

Step 1:

-1 -2 -3 -1 -2 -3 -1 -2 -2 -1 -3 -1 -3

Step 2:

64 37 62 -1 -2 -3 -1 -2 -2 -1 -3 -1 -3

Step 3:
Smallest non-negative element is : 37
Element corresponding to the index of 37 in the original array is 2
So element 2 appears exactly k times in the array

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to