Solution: Majority Element

Let's solve the Majority Element problem using the Knowing What To Track pattern.

Statement

Given an array, nums, having nn integers, return the majority element. An element will be considered a majority element if it occurs more than n/2⌊n / 2⌋ times in the array.

Note: It is safe to assume that the majority element always exists in the array.

Constraints

  • n==n == nums.length
  • 1n51041\leq n\leq 5* 10^4
  • 109
...