Trains the technique from
LeetCode 2342Max Sum of a Pair With Equal Sum of DigitsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A list of positive whole numbers reads values. The digit total of a number is what its decimal digits add up to.
Return the largest amount any two values at different positions add up to, given that their digit totals match, or -1 when no two positions have matching digit totals.
Example 1
The digit totals are six, eight, eight and six. The pair on six adds to ninety-three and the pair on eight to eighty-eight, so ninety-three wins.
Example 2
The three digit totals are all different, so no pair qualifies.
Example 3
All three values have a digit total of nine, so the two largest pair up.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_sum(values: list[int]) -> int:public int maximumSum(int[] values)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.