You get an integer array nums of length n. Return every value that appears more than ⌊n / 3⌋ times, in any order. When no value clears that bar, return an empty array.
⌊7 / 3⌋ = 2. Both 4 and 9 appear three times, which is more than 2. 2 appears once. [9,4] is also accepted.
⌊4 / 3⌋ = 1, and only -3 appears more than once.
⌊3 / 3⌋ = 1, and every value appears exactly once, which is not more than 1.
Constraints
n == nums.length1 <= n <= 5 · 10⁴-10⁹ <= nums[i] <= 10⁹Counting every value with a hash map is straightforward. Can you do it in O(n) time with only O(1) extra memory? The judge only checks the answer, so that part is up to you.
At most two values can clear the bar: three values with more than ⌊n / 3⌋ copies each would need more than n slots between them. So you only ever have to track two candidates.