Find if there is an element repeating itself n/k times
Posted
by gleb-pendler
on Stack Overflow
See other posts from Stack Overflow
or by gleb-pendler
Published on 2010-06-08T20:48:49Z
Indexed on
2010/06/08
21:02 UTC
Read the original article
Hit count: 264
You have an array size n
and a constant k
(whatever)
You can assume the the array is of int type (although it could be of any type)
Describe an algorithm that finds if there is an element(s) that repeats itself at least n/k
times... if there is return one. Do so in linear time (O(n)
)
The catch: do this algorithm (or even pseudo-code) using constant memory and running over the array only twice
© Stack Overflow or respective owner