Loading...
You are given an array nums of positive integers. The digit sum of a number is the sum of its decimal digits. For example, the digit sum of 43 is 4 + 3 = 7, and the digit sum of 900 is 9 + 0 + 0 = 9.
Consider every pair of positions i and j with i != j such that nums[i] and nums[j] have the same digit sum. Return the largest value of nums[i] + nums[j] among those pairs. If no pair of positions has matching digit sums, return -1.
Input: nums = [18,43,36,13,7]
Output: 54
Explanation: 18 and 36 both have digit sum 9, and their sum 54 is the largest available. The only other matching pair is 43 and 7 (digit sum 7), which sums to 50.
Input: nums = [10,12,19,14]
Output: -1
Explanation: The digit sums are 1, 3, 10, and 5, all different, so no pair qualifies.
nums.length ≤105nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.