Daily bit(e) of C++ #268, Common C++ interview problem: Majority element.
Majority, not "most frequent". As the problem definition says, you can rely on the input having a majority element.
Yes, that is precisely what majority means, the majority element has more than size/2 number of instances.
1 is a majority in {1,0,1,1,0,1,0} because it has 4 instances in an array of size 7.
{1,1,1,2,2,2,3,3,3} is not a valid input because it doesn't have a majority element.
Majority, not "most frequent". As the problem definition says, you can rely on the input having a majority element.
Yes, that is precisely what majority means, the majority element has more than size/2 number of instances.
1 is a majority in {1,0,1,1,0,1,0} because it has 4 instances in an array of size 7.
{1,1,1,2,2,2,3,3,3} is not a valid input because it doesn't have a majority element.