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