Values Above a Third
Return, in ascending order, every value that appears more than times in nums.
Requirements
- At most two values can qualify. Try the -space Boyer–Moore voting idea with two candidates.
Examples
EXAMPLE WALKTHROUGHone value
A guided view of the published example, not a trace of your code.
INPUT
[[3,2,3]]TASKfrequent_thirds()
EXPECTED OUTPUT
[3]Start with the input values shown in this example.
Example 1 of 3
Input: nums = [3,2,3]
Output: [3]
Explanation: one value
Input: nums = [1]
Output: [1]
Explanation: single
Input: nums = [1,2]
Output: [1,2]
Explanation: both qualify
Hint 1
Keep two candidates with counters; on a third distinct value, decrement both.
Hint 2
Verify the candidates with a second pass.