<p>You are given an integer array <code>nums</code>. You have to find the <strong>maximum</strong> sum of a pair of numbers from <code>nums</code> such that the <strong>largest digit </strong>in both numbers is equal.</p>

<p>For example, 2373 is made up of three distinct digits: 2, 3, and 7, where 7 is the largest among them.</p>

<p>Return the <strong>maximum</strong> sum or -1 if no such pair exists.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [112,131,411]</span></p>

<p><strong>Output:</strong> <span class="example-io">-1</span></p>

<p><strong>Explanation:</strong></p>

<p>Each numbers largest digit in order is [2,3,4].</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [2536,1613,3366,162]</span></p>

<p><strong>Output:</strong> <span class="example-io">5902</span></p>

<p><strong>Explanation:</strong></p>

<p>All the numbers have 6 as their largest digit, so the answer is <span class="example-io">2536 + 3366 = 5902.</span></p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [51,71,17,24,42]</span></p>

<p><strong>Output:</strong> <span class="example-io">88</span></p>

<p><strong>Explanation:</strong></p>

<p>Each number&#39;s largest digit in order is [5,7,7,4,4].</p>

<p>So we have only two possible pairs, 71 + 17 = 88 and 24 + 42 = 66.</p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= nums.length &lt;= 100</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution:
    def check_max_digit(self, num1, num2) -> bool:
        max_digit_one = 0
        max_digit_two = 0

        while(num1 > 0):
            remainder = num1 % 10
            num1 = num1 // 10
            if(remainder > max_digit_one):
                max_digit_one = remainder
        while(num2 > 0):
            remainder = num2 % 10
            num2 = num2 // 10
            if(remainder > max_digit_two):
                max_digit_two = remainder
        
        return (max_digit_one == max_digit_two)

    def maxSum(self, nums: List[int]) -> int:
        """
        given: array of int
                find max sum of two pairs that has largest digit
        output: max sum or -1 if doesn't exist
        """
        n = len(nums) #size

        total_combination_unique_pairs = n * (n - 1)/ 2
        count = 0
        max_sum = -1

        for i in range(len(nums)):
            for j in range(i + 1, len(nums)):
                if(self.check_max_digit(nums[i], nums[j])):
                    max_sum = max(max_sum, nums[i] + nums[j])
                    print(max_sum)
                else:
                    count += 1

        if(count == total_combination_unique_pairs):
            return -1
        else:
            return max_sum
        
    

472