Find majority element

Given an array of size n, which contains duplicate elements. Find and return the majority element which occurs more than n/2 times in the array.

Note : Return -1 if no majority element is present.

Input format :

Line 1 : Size of input array

Line 2 : Array elements (separated by space)

Sample Input 1 :
5
2 1 1 2 1
Sample Output 1 :
1

Login to submit your solution

Fb dab53a1a64929320dc7425896aa73fd9e5512b6ab52e414ff5f3ebb5cecc73eb

Share Problem