Majority Element
Medium 40 XPArraysHashing
Commonly asked at Amazon, Google, Microsoft
Read a list of integers where one value appears more than n / 2 times. Print that value. Can you do it with O(1) extra memory?
- Input
- One line of space-separated integers.
- Output
- The majority element.
Sample 1
Input
2 2 1 1 1 2 2
Output
2
Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.The solution unlocks after 3 submissions.