#K13501. Majority Element II
Majority Element II
Majority Element II
You are given an integer array. Your task is to find all the elements that appear more than \( \lfloor n/3 \rfloor \) times in the array, where \( n \) is the size of the array.
Note: If no such element exists, output an empty line.
Example:
- For the input array [3, 2, 3], the output is "3" as 3 appears twice and 2 appears once (threshold = 1).
- For the input array [1, 1, 1, 3, 3, 2, 2, 2], the output is "1 2".
You must read the input from stdin
and output the result to stdout
.
inputFormat
The input consists of two lines:
- The first line contains a single integer \( n \) which represents the number of elements in the array.
- The second line contains \( n \) space-separated integers.
outputFormat
Print the majority elements (those with frequency strictly greater than \( \lfloor n/3 \rfloor \)) in increasing order, separated by a space. If there are no such elements, print an empty line.
## sample3
3 2 3
3