FastPrepFastPrep
Problem Brief

Discount Tags

INTERNOA

One of the shops in HackerMall is offering discount coupons based on a puzzling problem. There are n tags where each tag has a value denoted by val[i]. A customer needs to choose the tags in such a way that the sum of values is even.

The goal is to find the maximum possible even sum of values of tags that can be chosen.

Note:

  • It is guaranteed that there is at least one tag with an even value.
  • The tags can have positive or negative values.
  • It can be possible to choose no tags at all.
  • Function Description

    Complete the function maximumPossibleEvenSum in the editor.

    maximumPossibleEvenSum has the following parameter:

    1. int val[]: an array of integers representing the values of tags

    Returns

    int: the maximum possible even sum of values of tags that can be chosen

    1Example 1

    Input
    val = [2, 3, 6, -5, 10, 1, 1]
    Output
    22
    Explanation

    Consider some of the following chosen tags and their corresponding sums:

    Chosen Tags Sum Is sum even?
    [2, 3, 6, 10, 1, 1] 23 No
    [2, 3, 6, -5, 10, 1, 1] 18 Yes
    [2, 6, 10, 1, 1] 20 Yes
    [2, 3, 6, 10, 1] 22 Yes

    The tags [2, 3, 6, 10, 1] sum to 22 which is even and is the maximum possible. Hence, the answer is 22.

    Constraints

    Limits and guarantees your solution can rely on.

    ๐ŸŽ๐ŸŽ
    public int maximumPossibleEvenSum(int[] val) {
      // write your code here
    }
    
    Input

    val

    [2, 3, 6, -5, 10, 1, 1]

    Output

    22

    Sign in to submit your solution.