[Java] easy solution
See similar question with a very detailed explanation - https://leetcode.com/problems/sum-of-subarray-minimums/discuss/178876/stack-solution-with-very-detailed-
See similar question with a very detailed explanation - https://leetcode.com/problems/sum-of-subarray-minimums/discuss/178876/stack-solution-with-very-detailed-explanation-step-by-step\n\n```\nclass Solution {\n    public int uniqueLetterString(String s) {\n        \n        int[] left = new int[s.length()];\n        int[] right = new int[s.length()];\n        \n        \n        Map<Character, Integer> m = new HashMap<>();\n        for(int i = 0; i < s.length(); ++i) {\n            var c = s.charAt(i);\n            left[i] = m.getOrDefault(c, -1);\n            m.put(c, i);\n        }\n        \n        m.clear();\n        \n        for(int i = s.length() - 1; i >= 0; --i) {\n            var c = s.charAt(i);\n            right[i] = m.getOrDefault(c, s.length());\n            m.put(c, i);\n        }\n        \n        \n        int result = 0;\n        for(int i = 0; i < s.length(); ++i) {\n            result += (i - left[i]) * (right[i] - i);\n        }\n        \n        return result;\n        \n    }\n}\n```
[]