Problem of the day
Input: ‘N’ = 9 ‘A’ = [2, 2, 1, 3, 1, 1, 3, 1, 1]
Output: 1
Explanation: The frequency of ‘1’ is 5, which is greater than floor(N / 2),
hence ‘1’ is the majority element.
The first line contains one integer ‘N’, denoting the number of elements in the
Array ‘A’.
The second line contains ‘N’ integers denoting the elements of the array ‘A’.
Return the majority element.
You don't need to print anything. Just implement the given function.
1 <= N <= 1e3
-1e9 <= A[i] <= 1e9
Time Limit: 1-sec
9
2 2 1 3 1 1 3 1 1
1
Input: ‘N’ = 9, ‘A’ = [2, 2, 1, 3, 1, 1, 3, 1, 1]
Output: 1
Explanation: The frequency of ‘1’ is 5, which is greater than floor(N / 2), hence ‘1’ is
The majority element.
1
4
4
5
-53 75 56 56 56
56