Banco público de perguntas reais para entrevistas: explore por empresa, categoria e tema
CodingSenior

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.

Empresas em que apareceu
LinkedInLinkedIn
Contextos reais

Onde essa pergunta já apareceu

Use esses exemplos para entender em que contexto ela costuma cair e adaptar sua prática.

LinkedInseniorfev. de 2025

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.

Anexos públicos

Materiais associados

Nenhum anexo público associado a esta pergunta.

Sinais de resposta forte
Você deixa claro por que escolheu essa abordagem e o que descartou.
Seu código vem acompanhado de testes mentais e edge cases relevantes.
Sua explicação ajuda o entrevistador a acompanhar o raciocínio em tempo real.
O que costuma enfraquecer a resposta
Entrar direto no código sem alinhar interpretação do problema.
Passar tempo demais em silêncio e só explicar no fim.
Ignorar complexidade, invariantes e estratégia de teste.

Continue a preparação com o banco completo

No app você encontra perguntas parecidas, compara empresas e aprofunda essa busca com mais filtros.