Majority Element
Recognize the pattern
Brute force idea
A straightforward first read of Majority Element is this: Count every element with a hash map. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
Better approach
The deeper shift in Majority Element is this: Boyer-Moore voting: maintain a candidate and counter. Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.
Key invariant
At the center of Majority Element is one steady idea: The majority element survives cancellation because it appears more than all others combined. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Watch out for
One easy way to drift off course in Majority Element is this: Not knowing Boyer-Moore — the trick is that the majority element always wins the vote. The fix is usually to return to the meaning of each move, not just the steps themselves.