🧽 Java Clean & Simple
\nclass Solution {\n    public int maximumSum(int[] nums) {\n        HashMap<Integer, Integer> map = new HashMap<>();\n        int result = -1;\n\n        for (
```\nclass Solution {\n    public int maximumSum(int[] nums) {\n        HashMap<Integer, Integer> map = new HashMap<>();\n        int result = -1;\n\n        for (int item : nums) {\n            int key = getNumberTotal(item);\n\n            if (!map.containsKey(key))\n                map.put(key, item);\n            else {\n                result = Math.max(result, map.get(key) + item);\n                map.put(key, Math.max(map.get(key), item));\n            }\n        }\n\n        return result;\n    }\n\n    int getNumberTotal(int num) {\n        int result = 0;\n        while (num > 0) {\n            result += num % 10;\n            num /= 10;\n        }\n\n        return result;\n    }\n}\n```\n\n**Update**:\n\nThanks for ***@harsh_ju_sharma***, we can use an int[82] arr to store the value as a map to save more time and memory!\nhttps://leetcode.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/discuss/2294703/java-on-but-space-optimised-explained-ttt\n\n*Definitely go check his post to get the full explanation!*\n\n\n```\nclass Solution {\n    public int maximumSum(int[] nums) {\n        int[] map = new int[82];\n        int result = -1;\n\n        for (int item : nums) {\n            int key = getNumberTotal(item);\n\n            if (map[key] != 0)\n                result = Math.max(result, map[key] + item);\n            map[key] = Math.max(map[key], item);\n        }\n\n        return result;\n    }\n\n    int getNumberTotal(int num) {\n        int result = 0;\n        while (num > 0) {\n            result += num % 10;\n            num /= 10;\n        }\n\n        return result;\n    }\n}\n```\n\n\n\n
['Java']