Given an array **arr[]** consisting of **N** integers, the task is to find all the array elements having frequency more than **⌊N/3⌋** in the given array.

**Examples:**

Input:arr[] = {5, 3, 5}Output:5Explanation:

The frequency of 5 is 2, which is more than N/3( = 3/3 = 1).

Input:arr[] = {7, 7, 7, 3, 4, 4, 4, 5}Output:4 7Explanation:

The frequency of 7 and 4 in the array is 3, which is more than N/3( = 8/3 = 2).

**Approach:** To solve the problem, the idea is to use Divide and Conquer technique. Follow the steps below to solve the problem:

- Initialize a function
**majorityElement()**that will return the count of majority element in the array from any index**left**to**right**. - Divide the given array
**arr[]**into two halves and repeatedly pass it to the function**majorityElement()**. - Initialize
**low**and**high**as**0**and**(N – 1)**respectively. - Compute the majority element using the following steps:
**If low = high:**Return**arr[low]**as the majority element.- Find the middle index,say
**mid**(=**(low + high)/2**). - Recursively call for both the
**left and right subarrays**as**majorityElement(arr, low, mid)**and**majorityElement(arr, mid + 1, high)**. - After completing the above steps, merge both the subarrays and return the majority element.

- Whenever the required majority element is found, append it to the resultant list.
- Print all the majority elements stored in the list.

Below is the implementation of the above approach:

## Python3

`# Python program for the above approach ` ` ` `class` `Solution: ` ` ` ` ` `# Function to find all elements that ` ` ` `# occurs >= N/3 times in the array ` ` ` `def` `majorityElement(` `self` `, a): ` ` ` ` ` `# If array is empty return ` ` ` `# empty list ` ` ` `if` `not` `a: ` ` ` `return` `[] ` ` ` ` ` `# Function to find the majority ` ` ` `# element by Divide and Conquer ` ` ` `def` `divideAndConquer(lo, hi): ` ` ` `if` `lo ` `=` `=` `hi: ` ` ` `return` `[a[lo]] ` ` ` ` ` `# Find mid ` ` ` `mid ` `=` `lo ` `+` `(hi ` `-` `lo)` `/` `/` `2` ` ` ` ` `# Call to the left half ` ` ` `left ` `=` `divideAndConquer(lo, mid) ` ` ` ` ` `# Call to the right half ` ` ` `right ` `=` `divideAndConquer(mid ` `+` `1` `, hi) ` ` ` ` ` `# Stores the result ` ` ` `result ` `=` `[] ` ` ` `for` `numbers ` `in` `left: ` ` ` `if` `numbers ` `not` `in` `right: ` ` ` `result.append(numbers) ` ` ` ` ` `result.extend(right) ` ` ` ` ` `# Stores all majority elements ` ` ` `ans ` `=` `[] ` ` ` ` ` `for` `number ` `in` `result: ` ` ` `count ` `=` `0` ` ` ` ` `# Count of elements that ` ` ` `# occurs most ` ` ` `for` `index ` `in` `range` `(lo, hi ` `+` `1` `): ` ` ` `if` `a[index] ` `=` `=` `number: ` ` ` `count ` `+` `=` `1` ` ` ` ` `# If the number is a ` ` ` `# majority element ` ` ` `if` `count > (hi ` `-` `lo ` `+` `1` `)` `/` `/` `3` `: ` ` ` `ans.append(number) ` ` ` ` ` `# Return the list of element ` ` ` `return` `ans ` ` ` ` ` `# Function Call ` ` ` `print` `(divideAndConquer(` `0` `, ` `len` `(a) ` `-` `1` `)) ` ` ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `# Given array a[] ` ` ` `a ` `=` `[` `7` `, ` `7` `, ` `7` `, ` `3` `, ` `4` `, ` `4` `, ` `4` `, ` `6` `] ` ` ` `object` `=` `Solution() ` ` ` ` ` `# Function Call ` ` ` `object` `.majorityElement(a) ` |

*chevron_right*

*filter_none*

**Output:**

[7, 4]

**Time Complexity:** O(N*log N)**Auxiliary Space:** O(log N)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Given an array of size n and a number k, find all elements that appear more than n/k times
- Length of longest subarray in which elements greater than K are more than elements not greater than K
- Two odd occurring elements in an array where all other occur even times
- Remove elements from the array which appear more than k times
- Sum of all numbers formed having 4 atmost X times, 5 atmost Y times and 6 atmost Z times
- GCD of elements occurring Fibonacci number of times in an Array
- Element which occurs consecutively in a given subarray more than or equal to K times
- Remove characters that appear more than k times
- Find the Number Occurring Odd Number of Times
- C/C++ Program to Find the Number Occurring Odd Number of Times
- First element occurring k times in an array
- Find the sum of all highest occurring elements in an Array
- Count substrings with each character occurring at most k times
- Check if max occurring character of one string appears same no. of times in other
- Sum of all minimum occurring elements in an Array
- Array elements that appear more than once
- Remove minimum elements from the array such that 2*min becomes more than max
- Find even occurring elements in an array of limited range
- Remove minimum elements from either side such that 2*min becomes more than max
- Longest subarray not having more than K distinct elements

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.