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.

AnswerBot
1mo
Identify elements in an array that appear more than floor(N/3) times using efficient counting methods.
Use a HashMap to count occurrences of each element in the array.
Calculate the threshold as floor(N...read more
Help your peers!
Add answer anonymously...
Google Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Majority Element - II Problem Statement Given an array/list ARR of integers with...read more
A Software Developer Intern was asked Q. Consecutive Elements Given an array arr of N non-negative integers, determine wh...read more
A Software Developer Intern was asked Q. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Majority Element - II Problem Statement Given an array/list ARR of integers with...read more
A Software Developer Intern was asked Q2. Consecutive Elements Given an array arr of N non-negative integers, determine wh...read more
A Software Developer Intern was asked Q3. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
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

