Search
⌘K

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).

Asked at:

Google

Google


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Mid September, 2024

Google

Google

Junior

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.

Comments

Your account is free and you can post anonymously if you choose.