2342. Max Sum of a Pair With Equal Sum of Digits Medium
1/**
2 * [2342] Max Sum of a Pair With Equal Sum of Digits
3 *
4 * You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j].
5 * Return the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the conditions.
6 *
7 * Example 1:
8 *
9 * Input: nums = [18,43,36,13,7]
10 * Output: 54
11 * Explanation: The pairs (i, j) that satisfy the conditions are:
12 * - (0, 2), both numbers have a sum of digits equal to 9, and their sum is 18 + 36 = 54.
13 * - (1, 4), both numbers have a sum of digits equal to 7, and their sum is 43 + 7 = 50.
14 * So the maximum sum that we can obtain is 54.
15 *
16 * Example 2:
17 *
18 * Input: nums = [10,12,19,14]
19 * Output: -1
20 * Explanation: There are no two numbers that satisfy the conditions, so we return -1.
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= nums.length <= 10^5
26 * 1 <= nums[i] <= 10^9
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/
32// discuss: https://leetcode.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn maximum_sum(nums: Vec<i32>) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_2342() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.