You are building an in-memory voting component for a lunch poll.
Task
Design and implement a hash-table–backed data structure that supports collecting votes for restaurant names and reporting the most popular restaurant(s).
Requirements
-
Each vote is a string
restaurantName
.
-
You must maintain vote counts as votes arrive.
-
Support these operations:
-
vote(restaurantName)
: record one vote for the restaurant.
-
getCount(restaurantName) -> int
: return the current vote count (0 if never seen).
-
getWinner() -> string
: return the restaurant with the highest vote count.
-
If there is a tie, return the lexicographically smallest name (or clearly state and implement a deterministic tie-break rule).
Constraints (assume)
-
Up to
N
total votes, where
N
can be large (e.g., 10^5–10^6).
-
Restaurant names can repeat and may include spaces.
-
Aim for near O(1) average time per
vote
/
getCount
using hashing.
What to discuss
-
Data structures used and why.
-
Time and space complexity.
-
Edge cases: no votes yet, ties, unseen restaurant names.