FastPrepMaximum Even Tag Sum
Problems/Maximum Even Tag Sum

Maximum Even Tag Sum

Visa logoVisa● EasyOA
QuestionFunctionExamples

Problem statement

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.

Function

maximumEvenSum(val: int[]) → int

Examples

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

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House RobberPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
public int maximumEvenSum(int[] val) {
  // write your code here
}
Checking account…