#12

Majority Element

Easy
All Problems

12. Majority Element#169

Easy📊 Arrays & HashingBoyer-Moore Voting

Find the element that appears more than n/2 times in an array.

Examples

Example 1:
Input: [[3,2,3]]
Output: 3
Example 2:
Input: [[2,2,1,1,1,2,2]]
Output: 2
Example 3:
Input: [[1]]
Output: 1

Why learn this

Multiple valid approaches (sorting, hash map, Boyer-Moore) teach problem-solving flexibility.

ArraysHash MapsBoyer-Moore Voting
Python 3Loading Python engine...
Click "Run Code" to test your solution