digitSumMap
to store the maximum two numbers for each sum of digits.maxSum
to -1
to keep track of the maximum sum.nums
array.
a. Calculate the sum of digits for the current number.
b. If the sum of digits is not in digitSumMap
, add it with the current number.
c. If it is in digitSumMap
, update the stored values if the current number is larger.
d. If there are two numbers stored for this sum of digits, calculate their sum and update maxSum
if it's larger.maxSum
.