Problems > Majority Element

Majority Element

Difficulty: 1100 2000 ms 128 MB

implementation

A value is a majority element if it appears more than N/2 times. Print it, or NONE if there is none.

Input: the first line has an integer N; the second line has N integers separated by spaces.

Output: the majority element or NONE.

Constraints:

  • 1 ≤ N ≤ 2000
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
5
3 3 4 3 2
Output 1
3
Input 2
4
1 1 2 2
Output 2
NONE

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.