python/java easy solution
\tclass Solution:\n\t\tdef maximumSum(self, nums: List[int]) -> int:\n\t\t\td = {}\n\t\t\tres = -1\n\t\t\tfor num in nums:\n\t\t\t\ts = sum([int(digit) for digi
\tclass Solution:\n\t\tdef maximumSum(self, nums: List[int]) -> int:\n\t\t\td = {}\n\t\t\tres = -1\n\t\t\tfor num in nums:\n\t\t\t\ts = sum([int(digit) for digit in str(num)])\n\t\t\t\tif s not in d:\n\t\t\t\t\td[s] = num\n\t\t\t\telse:\n\t\t\t\t\tres = max(res, d[s] + num)\n\t\t\t\t\td[s] = max(d[s], num)\n\t\t\treturn res\n\t\t\t\n\t\t\t\n\tclass Solution {\n\t\tpublic int maximumSum(int[] nums) {\n\t\t\tMap<Integer, Integer> map = new HashMap<>();\n\t\t\tint res = -1;\n\t\t\tfor (int num: nums) {\n\t\t\t\tint s = 0;\n\t\t\t\tfor (char digit: String.valueOf(num).toCharArray()) {\n\t\t\t\t\ts += Integer.valueOf(digit - \'0\');\n\t\t\t\t}\n\t\t\t\tif (!map.containsKey(s)) {\n\t\t\t\t\tmap.put(s, num);\n\t\t\t\t} else {\n\t\t\t\t\tres = Math.max(res, map.get(s) + num);\n\t\t\t\t\tmap.put(s, Math.max(map.get(s), num));\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}
[]