2815. Max Pair Sum in an Array Easy
1/**
2 * [2815] Max Pair Sum in an Array
3 *
4 * You are given an integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the largest digit in both numbers is equal.
5 * For example, 2373 is made up of three distinct digits: 2, 3, and 7, where 7 is the largest among them.
6 * Return the maximum sum or -1 if no such pair exists.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [112,131,411]</span>
11 * Output: <span class="example-io">-1</span>
12 * Explanation:
13 * Each numbers largest digit in order is [2,3,4].
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">nums = [2536,1613,3366,162]</span>
18 * Output: <span class="example-io">5902</span>
19 * Explanation:
20 * All the numbers have 6 as their largest digit, so the answer is <span class="example-io">2536 + 3366 = 5902.</span>
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [51,71,17,24,42]</span>
25 * Output: <span class="example-io">88</span>
26 * Explanation:
27 * Each number's largest digit in order is [5,7,7,4,4].
28 * So we have only two possible pairs, 71 + 17 = 88 and 24 + 42 = 66.
29 * </div>
30 *
31 * Constraints:
32 *
33 * 2 <= nums.length <= 100
34 * 1 <= nums[i] <= 10^4
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/max-pair-sum-in-an-array/
40// discuss: https://leetcode.com/problems/max-pair-sum-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn max_sum(nums: Vec<i32>) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2815() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.