2 Comments
Comment removed
Sep 26, 2023
Comment removed
Expand full comment

Majority, not "most frequent". As the problem definition says, you can rely on the input having a majority element.

Expand full comment
Comment removed
Sep 26, 2023
Comment removed
Expand full comment

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.

Expand full comment