#K64502. Majority Element Finder

    ID: 31989 Type: Default 1000ms 256MiB

Majority Element Finder

Majority Element Finder

Given an array of integers, your task is to find the majority element if it exists. The majority element is defined as the element that appears more than $$\left\lfloor \frac{n}{2} \right\rfloor$$ times in the array, where n is the size of the array.

If such an element exists, print the element. Otherwise, print None.

Example:

  • Input: 3\n3 2 3
    Output: 3
  • Input: 5\n1 1 2 3 4
    Output: None

inputFormat

The input is given via stdin and has the following format:

  1. An integer n representing the number of elements in the array.
  2. A line with n space-separated integers.

For example:

3
3 2 3

outputFormat

Output a single line to stdout:

  • The majority element if it exists, i.e. the element that appears more than $$\left\lfloor \frac{n}{2} \right\rfloor$$ times.
  • If no majority element exists, output None.
## sample
3
3 2 3
3