java.lang.Object
g2301_2400.s2342_max_sum_of_a_pair_with_equal_sum_of_digits.Solution

public class Solution extends Object
2342 - Max Sum of a Pair With Equal Sum of Digits.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <strong>positive</strong> integers. You can choose two indices <code>i</code> and <code>j</code>, such that <code>i != j</code>, and the sum of digits of the number <code>nums[i]</code> is equal to that of <code>nums[j]</code>.</p> <p>Return <em>the <strong>maximum</strong> value of</em> <code>nums[i] + nums[j]</code> <em>that you can obtain over all possible indices</em> <code>i</code> <em>and</em> <code>j</code> <em>that satisfy the conditions.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [18,43,36,13,7]</p> <p><strong>Output:</strong> 54</p> <p><strong>Explanation:</strong> The pairs (i, j) that satisfy the conditions are:</p> <ul> <li> <p>(0, 2), both numbers have a sum of digits equal to 9, and their sum is 18 + 36 = 54.</p> </li> <li> <p>(1, 4), both numbers have a sum of digits equal to 7, and their sum is 43 + 7 = 50.</p> </li> </ul> <p>So the maximum sum that we can obtain is 54.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [10,12,19,14]</p> <p><strong>Output:</strong> -1</p> <p><strong>Explanation:</strong> There are no two numbers that satisfy the conditions, so we return -1.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximumSum

      public int maximumSum(int[] nums)