← Questions
Most popular concert city from votes, with name variants and weights
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Microsoft's technical phone screen, last asked Sep 2025. It tests hashing, string normalization and clustering.
Fans vote for the city where a band should play next. Each vote names a city as free text. Return the city with the most votes. The interviewer then makes it harder: the same city appears under many spellings, and some votes count more than others.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
most_popular_city(votes: list[str]) -> str— returns the city with the most votes, breaking ties in a way you state. - Part 2:
most_popular_city(votes: list[str], aliases: dict[str, str]) -> str—aliasesmaps a normalized spelling to a canonical name. - Part 3:
most_popular_city_weighted(votes: list[tuple[str, int]], aliases: dict[str, str]) -> str— each vote carries a weight.
Example
aliases = {"nyc": "New York", "new york": "New York", "new york city": "New York",
"boston": "Boston", "chicago": "Chicago"}
["NYC", "Boston", "new york", " New York City ", "Boston", "Chicago"]
-> "New York" # 3 votes after trimming and lower-casing; Boston has 2
[("Boston", 1), ("NYC", 1), ("New York", 1), ("Boston", 3)]
-> "Boston" # Boston 4, New York 2
Constraints
- Up to 10^6 votes; city strings are short.
- Weights are positive integers.
Clarifying questions
- How should ties be broken?
- What happens to a vote whose spelling is not in the alias table?
- Is there a list of real cities to match against?
- Are weights per vote or per voter?
What a strong answer covers
- Part 1: a hash map of counts, O(n) time, and a stated tie rule.
- Part 2: normalization first (trim, lower-case, strip punctuation, collapse spaces), then the alias table; unknown spellings counted separately or reported.
- Beyond a fixed table, how you would cluster variants: rules (abbreviation lists), fuzzy string matching such as edit distance, phonetic keys, or embeddings; how to choose a similarity threshold; ambiguous names such as "Springfield" that need state or country.
- Part 3: add weights instead of 1; watch for overflow.
- How to evaluate and maintain the mapping: a labelled sample, precision and recall of merges, review of new unmatched spellings.
Follow-ups
- Votes stream in and the leader must be shown live.
- Return the top 3 cities.
- Two real cities share a name. How do you avoid merging them?
Where it's asked
- Microsoft · Technical phone screen · Last asked Sep 202560 min · One technical round
What it tests
hashing · string normalization · clustering
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
