[JAVA] Multiple approaches
Approach 0: Brute force\n\n\nclass Solution {\n    public int uniqueLetterString(String s) {\n        int count =0;\n        for(int i=0; i<s.length(); i++){\n 
**Approach 0:** Brute force\n\n```\nclass Solution {\n    public int uniqueLetterString(String s) {\n        int count =0;\n        for(int i=0; i<s.length(); i++){\n            for(int j=i; j<=s.length();j++){\n                String str = s.substring(i,j);\n                // System.out.println(str);\n                count += getCount(str);\n            }\n        }\n       \n    return count;\n    }\n    public int getCount(String str){\n        int[] alpha = new int[26];\n        for(int i=0; i<str.length(); i++){\n            int c = str.charAt(i)-\'A\';\n            alpha[c]++;\n        }\n        int count =0;\n            \n        for(int i=0; i<26; i++){\n            if(alpha[i]==1)count++;\n        }\n        return count;\n    }\n}\n```\n\n**Approach 1:** DP\n\n```\nclass Solution {\n    public int uniqueLetterString(String s) {\n        \n        int[] lastPosition = new int[26];\n        int[] currContribution = new int[26];\n        \n        int res = 0;\n        \n        for(int i=0; i<s.length(); i++){\n        \n            int c = s.charAt(i) - \'A\';\n            \n            int totalSubtringsAti = i+1;\n            // this includes duplicate contribution if i occurenced earlier\n            // lastposition[i] will be 0 if its unique sofar\n            \n            totalSubtringsAti -= lastPosition[c];\n            currContribution[c] = totalSubtringsAti;\n            \n            int curr = 0;\n            for(int j=0; j<26; j++){\n                curr += currContribution[j];\n            }\n            \n            res += curr;\n            lastPosition[c] = i+1;\n            \n        }\n        return res;\n    }\n}\n```\n\n```\nclass Solution {\n    public int uniqueLetterString(String s) {\n        int[][] index = new int[26][2];\n        int res=0, N=s.length(), mod=(int)Math.pow(10,9)+7;\n        for (int i = 0; i < 26; ++i) Arrays.fill(index[i],-1);\n        // find last 2 occurences of each char in s\n        for(int i=0; i<s.length(); i++){\n            int c = s.charAt(i)-\'A\';\n            res = (res + ((i-index[c][1])* (index[c][1]-index[c][0])) %mod )%mod;\n            index[c] = new int[]{index[c][1],i};\n        }\n        // count result\n        for(int c=0; c<26;c++){\n            res = (res + ((N-index[c][1])*(index[c][1]-index[c][0])) %mod) %mod;\n        }\n    return res;\n    }\n}\n```
['Java']