
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
What's special about a majority element ?
A majority element appears more than half the length of the array number of times.
If we tried a random index of the array, what's the probability that this index has a majority element ?
It's more than 50% if that array has a majority element.
Try a random index for a proper number of times so that the probability of not finding the answer tends to zero.