Approach hintTry it first, then revealHide
A hash map of counts works in O(n) space. For O(1) space, keep one candidate and a counter that rises on a match and falls otherwise, replacing the candidate whenever the counter is zero (Boyer-Moore voting).