Novo curso: Como conseguir vagas remotas em empresas que pagam $120k+/ano
NaGringa
CodingJunior

Leetcode 2098. Subsequence of Size K With the Largest Even Sum

Pick exactly k elements from an array to maximize their sum under the constraint that the sum must be even. Typical approach is greedy: take the k largest values, and if their sum is odd, adjust parity by swapping the smallest odd/even chosen element with the best opposite-parity candidate outside the selection (use sorting/heaps to find those quickly).

Empresas em que apareceu
GoogleGoogle
Contextos reais

Onde essa pergunta já apareceu

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

Googlejuniorset. de 2024

Given a sequence of digits of size S, return the subsequence that represents the largest possible number of size K that could be formed from the sequence maintaining the input order.

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.