GeeksforGeeks » Interview Questions

Leader of an Array

(3 posts)
  • Started 4 months ago by shrutig
  • Latest reply from sheldoncooper

Tags:

  1. sheldoncooper
    Member
    Posted 4 months ago #

    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)

  2. kartik
    Moderator
    Posted 4 months ago #

  3. sheldoncooper
    guest
    Posted 4 months ago #

    Thanks, the moore-boyer algo was really helpful..


Reply

You must log in to post.

RSS feed for this topic