Majority Element - II Problem Statement
Given an array/list ARR
of integers with length 'N', identify all elements that appear more than floor(N/3)
times within the array/list.
Input:
T (number of test cases)
For each test case:
- N (number of elements in the array)
- A sequence of N space-separated integers representing the array elements
Output:
For each test case, output the majority elements, each separated by a space. Output the result for each test case on a new line. The order of majority elements does not need to be maintained.
Example:
Input:
2
7
3 2 3 1 4 3 3
6
1 1 2 2 3 3
Output:
3
1 2 3
Constraints:
1 <= T <= 100
3 <= N <= 5000
1 <= ARR[i] <= 10^5
Time Limit: 1 sec
Note:
You don’t need to print anything; it's already handled. Implement the given function to solve the problem.
Be the first one to answer
Add answer anonymously...
Top Google Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Google Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app