A majority element in an array A[]
of size n is an element that appears more than n/2 times (and hence there is at
most one such element).
def find(a,x):
for i in set(a):
c=a.count(i)
if c>x:
return i
a=list(map(int,input().split()))
x=len(a)/2
k=find(a,x)
if k:
print(k)
else:
print ("No Majority element")
Input:
1 2 3 5 9 3 3 3 3 4 3 3 3 3
Output
3
No comments:
Post a Comment