Find number which is occur more than N/3 times in array. not N/2 times? just look at question first.
Without Using Moore's Algorithms.
Find number which is occur more than N/3 times in array. not N/2 times? just look at question first.
Without Using Moore's Algorithms.
You will need to take into account the maximum (What is your worst scenario). Unless you have not checked all elements in your array, 2 can compete till the end.
Lets assume you have the following array:
[1,2,3,1,2,2,1,2]
Based on this example you can see you will need to run over all of teh elements one time: O(n)