Majority Element - II Problem Statement
You are given an array ARR
of integers of length N
. Your task is to find all the elements that occur strictly more than floor(N/3)
times in the given array.
Input:
The first line contains a single integer T
denoting the number of test cases.
For each test case:
The first line contains an integer N
indicating the number of elements in the array.
The second line contains N
space-separated integers representing the elements of the array.
Output:
For each test case, output all the majority elements separated by a space.
Print the result for each test case in a separate line. The elements can be in any order.
Example:
Input:
2
7
3 3 4 2 4 4 2
6
5 5 5 5 2 2
Output:
4 2
5
Constraints:
1 ≤ T ≤ 100
3 ≤ N ≤ 5000
1 ≤ ARR[i] ≤ 10^5
- Time Limit: 1 sec
Note:
You are not required to print anything explicitly; only implement the described function to obtain the results.
Be the first one to answer
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

