Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Majority Element - Python Question

Challenges • Asked over 4 years ago by Anonymous

Anonymous Commented on Apr 09, 2020:

Is it not possible to create a O(n) solution?

By creating a hashmap where the keys are the digits and the values are the number of times that the digits appear, and then looking for the hashmap value that is greater than n / 2?

By using a sort you also run the risk of using a bad sort algo that could be O(n2) - not all languages make it clear which sort algo is actually used.

Link to problem: Majority Element.