2815. 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. 123456789101112131415161718192021class Solution { int digit(int x) { int res = 0; while(x) { res = max(res, x % 10); x /= 10; } return res; }public: int maxSum(vector<int>& nums) { int res = -1; for(int i = 0; i < nums.size(); i++) { for(int j = i + 1; j < nums.size(); j++) { if(digit(nums[i]) == digit(nums[j])) res = max(res, nums[i] + nums[j]); } } return res; }};