You're analyzing the results of a modern city election where voters can cast their ballots for multiple candidates or choose not to vote at all. Here's the twist: when someone votes for multiple candidates, their single vote gets equally split among all their chosen candidates.
For example, if Alice votes for both candidate "John" and candidate "Mary", then John receives 0.5 votes and Mary receives 0.5 votes from Alice.
Your task: Determine which candidate(s) won the election by receiving the most total votes. If there's a tie for the highest vote count, return all tied candidates.
Input: A database table Votes with columns voter (varchar) and candidate (varchar). Each row represents one voter's choice for one candidate.
Output: The name(s) of the winning candidate(s), ordered alphabetically.
Input & Output
Visualization
Time & Space Complexity
Single pass through data with efficient window function calculations
Space proportional to number of unique candidates (k), not total votes (n)
Constraints
- 1 โค number of votes โค 104
- 1 โค voter.length, candidate.length โค 20
- voter and candidate contain only lowercase English letters
- Each voter can vote for multiple candidates or not vote at all
- The combination (voter, candidate) is unique in the table