GeeksforGeeks » Interview Questions
Leader of an Array
(3 posts)-
Given an array A of integers of size N, the leader of the array is the element which occurs more than half of the size of the array times. i.e. if the array A={1,3,5,2,4,2,4,2,2,2} then the leader of the array will not be 2 as it occurs exactly 5 times, thus it has to occur 6 or more times to be the leader.
Size of array can be from 0 to 10000
The array elements can range from 0 to 2147483647
Expected worst case running complexity=O(n)
Expected worst case space complexity=O(1) -
Looks similar to http://www.geeksforgeeks.org/archives/503
-
Thanks, the moore-boyer algo was really helpful..
Reply
You must log in to post.