✅ [TS] 100% Faster 118ms | HashMap | Easy to understand
\nconst maximumSum = (nums: number[]): number => {\n    const getDigitSum = (num: number): number => {\n        let sum = 0;\n\n        while (num > 0) {\n     
```\nconst maximumSum = (nums: number[]): number => {\n    const getDigitSum = (num: number): number => {\n        let sum = 0;\n\n        while (num > 0) {\n            sum += num % 10;\n            num = Math.floor(num / 10);\n        }\n\n        return sum;\n    }\n\n    const map = new Map<number, number>();\n    let ans: number = -1;\n\n    for (let i = 0; i < nums.length; i++) {\n        const sum = getDigitSum(nums[i]);\n\n        if (map.has(sum)) {\n            const curr = map.get(sum)!\n            const max = Math.max(nums[i], curr);\n\n            ans = Math.max(ans, curr + nums[i]);\n\n            map.set(sum, max);\n        } else {\n            map.set(sum, nums[i])\n        }\n\n    }\n\n    return ans;\n}\n```\nLet me know in comments if you have any doubts. I will be happy to answer.\nPlease upvote if you found the solution useful.
['TypeScript', 'JavaScript']