Max Sum of a Pair With Equal Sum of Digits LeetCode solution in JavaScript

1
var maximumSum = function (nums) {
2
let sums = nums.map((x) =>
3
x
4
.toString()
5
.split("")
6
.map(Number)
7
.reduce((a, b) => a + b, 0)
8
);
9
let max = -1;
10
let map = sums.reduce((a, b, c) => {
11
a[b] ??= [];
12
a[b].push(nums[c]);
13
return a;
14
}, {});
15
Object.values(map).forEach((x) => {
16
if (x.length > 1) {
17
let temp = x.sort((a, b) => b - a);
18
max = Math.max(max, temp[0] + temp[1]);
19
}
20
});
21
return max;
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0