Majority Element (>N/3)

Hard Problems: N-Sum & Hashing DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Find all elements in an array that appear more than N/3 times, Arrays, Hashing, Frequency Counting, Boyer-Moore Voting Algorithm, Time Complexity, Space Complexity, Loops, Conditional Statements, Map, boyer-moore voting algorithm, brute force, frequency counting, array algorithms, time complexity analysis, Moore's Voting Algorithm.

Given an array of N integers, find all elements that appear more than N/3 times in the array. If no such element exists, return an empty list. Input Specification: The first line contains an integer N, the size of the array. The second line contains N space separated integers representing the elements of the array. Output Specification: Print the majority elements, space separated. If there are no such elements, print nothing or an empty line (depending on interpretation, but typically an empty line for competitive programming if no output is required). Example 1: Input: 5 1 2 2 3 2 Output: 2 Explanation: Here we can see that the Count(1) = 1, Count(2) = 3 and Count(3) = 1. Therefore, the count of 2 is greater than N/3 times. Hence, 2 is the answer. Example 2: Input: 6 11 33 33 11 33 11 Output: 11 33 Explanation: Here we can see that the Count(11) = 3 and Count(33) = 3. Therefore, the count of both 11 and 33 is greater than N/3 times. Hence, 11 and 33 is the answer.