In this tutorial, I am going to discuss a very interesting problem find N/3 repeated number in an array.
Given an array of size n, Write a code to find all the elements that appear more than n/3 times.
NOTE: We have to solve this problem in linear time and in O(1) space.
Example 1:
Input : [3, 2, 3]
Output: 3
In this example, The size of this array is 3. We have to find all the numbers which occurred more than n/3 where n is the size of the array. The number 3 appears more than 1 times.
Example 2:
Input: [1, 1, 1, 3, 3, 2, 2, 2]
Output:[1, 2]