Let 1 N Unsorted Array N Positive Intergers See One Elements Majority Element Q37198882

Let A = [A[1],…,A[n]] be an unsorted array of npositive intergers. See if one of the elements is a majorityelement.


Answer


A majority element in an array A[](sorted/unsorted) of size n isan element that appears more than n/2 times.

Ex:-

Input : {3, 3, 4, 2, 4, 4, 2, 4, 4}Output : 4 Input : {3, 3, 4, 2, 4, 4, 2, 4}Output : No Majority Element

majority element in an unsorted array can be find in 3 ways:

1) METHOD 1 (Basic)
The basic solution is to have two for loops and keep track of maxcount for all distinct elements. If max count

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.