FastPrepDiscount Tags
Problems/Discount Tags

Discount Tags

MathWorks logoMathWorks● EasyINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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

maximumPossibleEvenSum(val: int[]) → int

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

Examples

Example 1

val = [2, 3, 6, -5, 10, 1, 1]return = 22

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

  • 🍎🍎

More MathWorks interview questions

  • Earliest Time to Schedule a MeetingOA · Seen Nov 2026
  • Minimum Cost to Serve Requests on a RingOA · Seen Nov 2026
  • Minimum Tree Diameter After Removing K LeavesOA · Seen Nov 2026
  • Cities on Shortest Delivery RoutesOA · Seen Nov 2026
  • Repeated Mirror XOROA · Seen Nov 2026
  • Beautiful ArrangementONSITE INTERVIEW · Seen Jul 2026
  • Find Minimum Cost to Remove Array ElementsONSITE INTERVIEW · Seen Jul 2026
  • Group Shifted StringsONSITE INTERVIEW · Seen Jul 2026
  • Longest Valid ParenthesesONSITE INTERVIEW · Seen Jul 2026
  • Balancing TeamsOA · Seen Nov 2025

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Server InvestmentRippling · OARippling interview questions
  • Book Reading EveningsGoogle · OAGoogle interview questions
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Minimum Project Bid CostNVIDIA · OANVIDIA interview questions
  • Minimum AmountBelvedere Trading · OA
  • Maximum Income from Asset TradingJefferies · OA
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
  • Economical TripAccenture · OAAccenture interview questions
  • Best Time to Buy and Sell StockFlexTrade · OAFlexTrade interview questions

MathWorks interview experiences

  • MathWorks SWE Intern Phone Screens: 1 Experience
  • MathWorks Software Engineer in Test OA and HireVue: 1 Experience
All MathWorks interview questionsSee MathWorks hiring insights
Saved
class Solution {
    public int maximumPossibleEvenSum(int[] val) {
      // write your code here
    }

}
Checking account…