Majority Element II

Medium · Arrays & Strings · about 20 minutes

Asked at Amazon, Meta, Microsoft, Google, Bloomberg.

nums has length n. Return every value that occurs more than ⌊n / 3⌋ times, in any order. There can be at most two. Aim for O(n) time and O(1) extra memory.

Related guides