Algorithms
Easy
2815
2902
Max Pair Sum in an Array
max-pair-sum-in-an-array
"""
You are given a 0-indexed integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the maximum digit in both numbers are equal.

Return the maximum sum or -1 if no such pair exists.

Example 1:

Input: nums = [51,71,17,24,42]
Output: 88
Explanation:
For i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88.
For i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.
It can be shown that there are no other pairs with equal maximum digits, so the answer is 88.

Example 2:

Input: nums = [1,2,3,4]
Output: -1
Explanation: No pair exists in nums with equal maximum digits.


Constraints:

 * 2 <= nums.length <= 100
 * 1 <= nums[i] <= 104
"""
class Solution:
    def maxSum(self, nums: List[int]) -> int:
        
You are given a 0-indexed integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the maximum digit in both numbers are equal.

Return the maximum sum or -1 if no such pair exists.

Example 1:

Input: nums = [51,71,17,24,42]
Output: 88
Explanation:
For i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88.
For i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.
It can be shown that there are no other pairs with equal maximum digits, so the answer is 88.

Example 2:

Input: nums = [1,2,3,4]
Output: -1
Explanation: No pair exists in nums with equal maximum digits.


Constraints:

 * 2 <= nums.length <= 100
 * 1 <= nums[i] <= 104


Please complete the code below to solve above prblem:
```python
class Solution:
    def maxSum(self, nums: List[int]) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [51,71,17,24,42] }
assert my_solution.maxSum(**test_input) == 88

test_input = { "nums": [1,2,3,4] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [31,25,72,79,74] }
assert my_solution.maxSum(**test_input) == 146

test_input = { "nums": [84,91,18,59,27,9,81,33,17,58] }
assert my_solution.maxSum(**test_input) == 165

test_input = { "nums": [8,75,28,35,21,13,21] }
assert my_solution.maxSum(**test_input) == 42

test_input = { "nums": [35,52,74,92,25,65,77,1,73,32] }
assert my_solution.maxSum(**test_input) == 151

test_input = { "nums": [68,8,100,84,80,14,88] }
assert my_solution.maxSum(**test_input) == 172

test_input = { "nums": [53,98,69,64,40,60,23] }
assert my_solution.maxSum(**test_input) == 167

test_input = { "nums": [21,76] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [99,63,23,70,18,64] }
assert my_solution.maxSum(**test_input) == 127

test_input = { "nums": [21,21,78] }
assert my_solution.maxSum(**test_input) == 42

test_input = { "nums": [58,88,58,99,26,92] }
assert my_solution.maxSum(**test_input) == 191

test_input = { "nums": [10,24,25,20,92,73,63,51] }
assert my_solution.maxSum(**test_input) == 76

test_input = { "nums": [87,6,17,32,14,42,46,65,43,9] }
assert my_solution.maxSum(**test_input) == 111

test_input = { "nums": [96,46,85,19,29] }
assert my_solution.maxSum(**test_input) == 125

test_input = { "nums": [5,24] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [26,76,24,96,82,97,97,72,35] }
assert my_solution.maxSum(**test_input) == 194

test_input = { "nums": [77,82,30,94] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [76,94,51,82,3,89,52,96] }
assert my_solution.maxSum(**test_input) == 190

test_input = { "nums": [27,59,57,97,6,46,88,41,52,46] }
assert my_solution.maxSum(**test_input) == 156

test_input = { "nums": [17,2] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [62,69] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [63,24,1] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [55,46,4,61,78,21,85,52,83,77] }
assert my_solution.maxSum(**test_input) == 168

test_input = { "nums": [21,73,2,80,99,98,89] }
assert my_solution.maxSum(**test_input) == 197

test_input = { "nums": [94,63,50,43,62,14,83,91] }
assert my_solution.maxSum(**test_input) == 185

test_input = { "nums": [66,17,17,35,46,77,7,15,38] }
assert my_solution.maxSum(**test_input) == 112

test_input = { "nums": [61,90,34,29,68,35] }
assert my_solution.maxSum(**test_input) == 119

test_input = { "nums": [18,82,78] }
assert my_solution.maxSum(**test_input) == 160

test_input = { "nums": [8,71,2,59,70,12] }
assert my_solution.maxSum(**test_input) == 141

test_input = { "nums": [55,88,59] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [49,47,46,65,37,24,75,81,54,39] }
assert my_solution.maxSum(**test_input) == 122

test_input = { "nums": [73,79,48,45,57,73,51,78,67,78] }
assert my_solution.maxSum(**test_input) == 156

test_input = { "nums": [2,82,80,74,34,54,65] }
assert my_solution.maxSum(**test_input) == 162

test_input = { "nums": [9,62,85,95,36,62,21,38,16,12] }
assert my_solution.maxSum(**test_input) == 124

test_input = { "nums": [50,80,34,9,86,20,67,94,65,82] }
assert my_solution.maxSum(**test_input) == 168

test_input = { "nums": [79,74,92,84,37,19] }
assert my_solution.maxSum(**test_input) == 171

test_input = { "nums": [85,20,79] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [89,55,67,84,3] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [16,44,2,54,58,94] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [71,14,24,13,21,14,100,18,84,37] }
assert my_solution.maxSum(**test_input) == 108

test_input = { "nums": [13,26] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [82,30,53,72,56,94,72,67] }
assert my_solution.maxSum(**test_input) == 144

test_input = { "nums": [14,80,92,65,85,70] }
assert my_solution.maxSum(**test_input) == 165

test_input = { "nums": [81,39,43,31,53,43,87,19,93] }
assert my_solution.maxSum(**test_input) == 168

test_input = { "nums": [27,12,80,38,94,92,67,54,56,20] }
assert my_solution.maxSum(**test_input) == 186

test_input = { "nums": [52,32,24,6,3,89,100,3,5,3] }
assert my_solution.maxSum(**test_input) == 57

test_input = { "nums": [93,1,13,88,47,48,46,63] }
assert my_solution.maxSum(**test_input) == 136

test_input = { "nums": [3,55,40,93,97,37,31,31] }
assert my_solution.maxSum(**test_input) == 190

test_input = { "nums": [58,41,10,74,40,17] }
assert my_solution.maxSum(**test_input) == 91

test_input = { "nums": [58,33,78,53,88,1,15,44,82] }
assert my_solution.maxSum(**test_input) == 170

test_input = { "nums": [41,48,96,71,35,89,57,71] }
assert my_solution.maxSum(**test_input) == 185

test_input = { "nums": [43,4,69,29,37,50] }
assert my_solution.maxSum(**test_input) == 98

test_input = { "nums": [65,88,2] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [86,42,59,44,76,6] }
assert my_solution.maxSum(**test_input) == 86

test_input = { "nums": [29,96,1,10,27,78,56,62] }
assert my_solution.maxSum(**test_input) == 125

test_input = { "nums": [100,48,6] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [33,17] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [8,91] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [91,13,72,42,28] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [5,53,35,88,77,1,66,57] }
assert my_solution.maxSum(**test_input) == 134

test_input = { "nums": [50,27,52,70,67,60,65] }
assert my_solution.maxSum(**test_input) == 137

test_input = { "nums": [84,82,31,45,94,62,45,32] }
assert my_solution.maxSum(**test_input) == 166

test_input = { "nums": [61,61,61,23,47,34,21,6,65,25] }
assert my_solution.maxSum(**test_input) == 126

test_input = { "nums": [60,21,11,99] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [22,83,62,12,63,100,41,33] }
assert my_solution.maxSum(**test_input) == 125

test_input = { "nums": [92,58,85] }
assert my_solution.maxSum(**test_input) == 143

test_input = { "nums": [93,5,46,26,25,36,27,12,30] }
assert my_solution.maxSum(**test_input) == 82

test_input = { "nums": [52,30,16] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [22,57,33,26,76,14,67] }
assert my_solution.maxSum(**test_input) == 143

test_input = { "nums": [90,72,37,30] }
assert my_solution.maxSum(**test_input) == 109

test_input = { "nums": [44,87,16] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [19,12,52,8,3,58] }
assert my_solution.maxSum(**test_input) == 66

test_input = { "nums": [88,52,35,6,58,47,62,82,47,86] }
assert my_solution.maxSum(**test_input) == 174

test_input = { "nums": [84,1,48,76,16,10,11,60] }
assert my_solution.maxSum(**test_input) == 132

test_input = { "nums": [12,60,69,63,78,22,28] }
assert my_solution.maxSum(**test_input) == 123

test_input = { "nums": [16,28,82,77,41,22] }
assert my_solution.maxSum(**test_input) == 110

test_input = { "nums": [97,31,63,2,94,14,47] }
assert my_solution.maxSum(**test_input) == 191

test_input = { "nums": [93,100,45,74,31,41,84,90,18,21] }
assert my_solution.maxSum(**test_input) == 183

test_input = { "nums": [21,12,38,64,57,24] }
assert my_solution.maxSum(**test_input) == 33

test_input = { "nums": [33,17,99,2,58,59,72,9,62] }
assert my_solution.maxSum(**test_input) == 158

test_input = { "nums": [36,11,23,98,14,89,90,53] }
assert my_solution.maxSum(**test_input) == 188

test_input = { "nums": [57,90,5,78,84,51] }
assert my_solution.maxSum(**test_input) == 162

test_input = { "nums": [73,73,76,48,30] }
assert my_solution.maxSum(**test_input) == 149

test_input = { "nums": [2,74,37,75] }
assert my_solution.maxSum(**test_input) == 149

test_input = { "nums": [84,35,65,12] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [95,46,23,81,35] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [64,76,46,54,64,94,90,95] }
assert my_solution.maxSum(**test_input) == 189

test_input = { "nums": [77,52,74,84,47,89,53] }
assert my_solution.maxSum(**test_input) == 151

test_input = { "nums": [29,31,52,12,89,88,10,18] }
assert my_solution.maxSum(**test_input) == 118

test_input = { "nums": [28,57,28,41,25,89,20] }
assert my_solution.maxSum(**test_input) == 56

test_input = { "nums": [31,28] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [51,1,98,73,84,11,100,100,75] }
assert my_solution.maxSum(**test_input) == 200

test_input = { "nums": [76,2,26,49,78,36,2,70,64] }
assert my_solution.maxSum(**test_input) == 146

test_input = { "nums": [34,63,21,49] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [35,19,1,21,11,59,38] }
assert my_solution.maxSum(**test_input) == 78

test_input = { "nums": [1,35,74,58,56,54,75] }
assert my_solution.maxSum(**test_input) == 149

test_input = { "nums": [20,49] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [97,92,13,30] }
assert my_solution.maxSum(**test_input) == 189

test_input = { "nums": [89,49,10,36,37] }
assert my_solution.maxSum(**test_input) == 138