Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Design an Algorithm to Elect a Restaurant for a Team Outing
Design an algorithm to elect a restaurant from a set of choices for a team outing. Each team member can select n options in their order of preference. The option wins as soon as more than 50% of first votes are there. When they are not, we remove the lowest voted option from everyone's ballot and repeat the process until we find a winner. Example: Restaurants: A, B, C Ballots: Ballot 1: [A, B, C] Ballot 2: [A, B, C] Ballot 3: [B, C, A] Ballot 4: [B, A, C] Ballot 5: [C, A, B] First Tally: The first-rank choices on the 5 ballots are A, A, B, B, C Candidate C has the lowest number of votes (just one vote from Ballot 5), thus it is removed. Updated Ballots After Removing C: Ballot 1: [A, B] Ballot 2: [A, B] Ballot 3: [B, A] Ballot 4: [B, A] Ballot 5: [A, B] Second Tally: The new first-rank choices on the 5 ballots become A, A, B, B, A Candidate A wins because A now has 3 votes, which is more than 50% of the total.
Asked at:
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late February, 2025
Senior
Design an algorithm to elect a restaurant from a set of choices for a team outing. Each team member can select n options in their order of preference. The option wins as soon as more than 50% of first votes are there. When they are not, we remove the lowest voted option from everyone's ballot and repeat the process until we find a winner. Example: Restaurants: A, B, C Ballots: Ballot 1: [A, B, C] Ballot 2: [A, B, C] Ballot 3: [B, C, A] Ballot 4: [B, A, C] Ballot 5: [C, A, B] First Tally: The first-rank choices on the 5 ballots are A, A, B, B, C Candidate C has the lowest number of votes (just one vote from Ballot 5), thus it is removed. Updated Ballots After Removing C: Ballot 1: [A, B] Ballot 2: [A, B] Ballot 3: [B, A] Ballot 4: [B, A] Ballot 5: [A, B] Second Tally: The new first-rank choices on the 5 ballots become A, A, B, B, A Candidate A wins because A now has 3 votes, which is more than 50% of the total.
Late February, 2025
Senior
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.