Votes Tally
There are k candidates numbered 0 to k - 1, and votes lists the candidate chosen on each ballot. Return a list of length k where item c is how many votes candidate c received (0 if none). Hint: np.bincount has a minlength option.
Example 1
votes [1,0,1,1]
k 3
returns [1,3,0]
Candidate 0 got 1 vote, candidate 1 got 3, candidate 2 got none.
Constraints
1 <= len(votes) <= 1001 <= k <= 10and every vote is from 0 tok - 1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Add Column OffsetsEasy
- Age GroupsEasy
- All DifferentEasy
- Average of Chosen RowsEasy
- Average of Top ThreeEasy
- Biggest JumpEasy
- Brighten ImageEasy
- Bucket CountsEasy