Asked inDE Shaw,Associate Developer Intern

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...
DE Shaw Associate Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter