votes lists the candidate numbers from the ballots, one number per ballot. There are n ballots in total.
Return every candidate that received more than ⌊n / 3⌋ votes, in any order.
Try to do it in linear time with O(1) extra memory.votes=[4, 7, 4, 2, 7, 4] → [4]
There are 6 votes, so a candidate needs more than 2. Candidate 4 has three, 7 has two and 2 has one: only 4 qualifies.
votes=[-5, 8] → [-5, 8]
The bar is more than 0 votes, so both qualify.
votes=[1, 2, 3, 1, 2, 3] → []
Each has exactly a third of the votes, but strictly more is needed, so the list is empty.
votes) ≤ 5·10⁴votes[i] ≤ 10⁹votes=[4, 7, 4, 2, 7, 4]
[4]
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.