Problem · Array
Maximum Even Tag Sum
A shop has n tags, each with a value val[i], which may be positive or negative.
A customer wants to choose a set of tags such that:
- The sum of the chosen tag values is even.
- The sum is as large as possible.
Additional notes:
- There is at least one tag with an even value.
- You may choose any number of tags, including zero.
Your task is to determine the maximum possible even sum that can be formed using any subset of the given tags.
Return this maximum even sum.
Examples
01 · Example 1
val = [2, 3, 6, -6, 10, 1, 1] return = 22
One valid choice is [2, 3, 6, 10, 1], whose sum is 22. Choosing both 1 tags would make the positive-tag sum odd, and adding -6 would only reduce the sum, so the maximum even sum is 22.
More Visa problems
- Transform Binary MatrixOA · Seen Jun 2026
- Minimum Cost to Select People for Skill QuotasOA · Seen May 2026
- Longest Selectable Non-Decreasing SubarrayOA · Seen Apr 2026
- Maximize Capped Contribution SumOA · Seen Apr 2026
- Previous Bus DepartureOA · Seen Dec 2025
- Largest Square Area in CityscapeSeen Jun 2025
public int maximumEvenSum(int[] val) {
// write your code here
}val[2, 3, 6, -6, 10, 1, 1]
expected22
checking account