4. Majority Element

The majority element appears more than ⌊n / 2⌋ times and always exists. Return it, ideally in O(n) time and O(1) extra space.

Example 1

Input: nums = [3,1,3]
Output: 3

Example 2

Input: nums = [6,5,5]
Output: 5
Hint 1

Pair up each majority vote with a different vote and cancel them. What survives?

ArrayCounting