Problem 244522 · easy · Level 02 Linear Data Structures

Vote Tally

hash maps · counting

A class election records every ballot as the candidate's name. Given the list votes, return a dictionary mapping each candidate to the number of votes they received. Candidates with zero votes do not appear (the function only knows about names on ballots).

Examples

Input:  votes = ["ana", "bo", "ana"]
Output: {"ana": 2, "bo": 1}

Input:  votes = []
Output: {}

Constraints

  • 0 <= len(votes) <= 10**5
  • Names are non-empty lowercase strings.
  • Target complexity: O(n) time.

Goals

  • Count occurrences with a dictionary
  • Return a plain dict built in one pass
Starting Python…