Skip to the code
+25 XP

#69 Votes Above a Third

medium

A design review lets each reviewer vote for one mockup number. Mockups chosen by more than a third of the reviewers move on.

Write aboveAThird(nums) that returns every value appearing more than nums.length / 3 times, sorted ascending. Use O(1) extra memory.

Example 1

Input: nums = [3,1,3,2,3,1,1]
Output: [1,3]

1 and 3 each appear 3 times out of 7, more than 7 / 3.

Example 2

Input: nums = [1,2,3]
Output: []

Each value appears once, which is not more than 3 / 3 = 1.

Constraints

  • 0 <= nums.length <= 5 * 10^5
  • -10^9 <= nums[i] <= 10^9
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).