Compute most popular location with weights
Company: Microsoft
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates a candidate's ability to perform weighted aggregation, data cleaning, tie-breaking logic, and handling of malformed or missing text fields using SQL and/or Python.
Tables
votes(voter_id INT, location_text VARCHAR(100), weight INT)
Hints
- Filter out rows where TRIM(location_text) is NULL or an empty string before aggregating.
- Use COALESCE(weight, 1) to apply the default weight, then GROUP BY location_text and filter to rows with the maximum SUM(weight).