Novo curso: Como conseguir vagas remotas em empresas que pagam $120k+/ano
NaGringa
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.

Próximo passo

Depois de treinar essa pergunta, vale abrir outras do mesmo tipo e da mesma senioridade para comparar padrões de resposta.

Isso ajuda a sair da memorização de uma resposta só e entrar em repertório real de entrevista.

Continue a preparação com o banco completo

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