Simple Java 2 Pointer
\nclass Solution {\n    \n    int MOD = 1_000_000_007;\n    \n    public int uniqueLetterString(String s) {\n        \n        int result = 0;\n        \n      
```\nclass Solution {\n    \n    int MOD = 1_000_000_007;\n    \n    public int uniqueLetterString(String s) {\n        \n        int result = 0;\n        \n        for(char ch = \'A\';ch <= \'Z\'; ++ch){\n            result = (result + uniqueSubstrings(s,ch))%MOD;\n        }\n        \n        return result;\n                \n    }\n    \n    int uniqueSubstrings(String s, char ch){\n        int l = 0;\n        int prevChIndex = -1;\n        int cnt = 0;\n        int result = 0;\n        \n        for(int r=0;r<s.length();++r){\n            if(s.charAt(r) == ch){                \n                prevChIndex = r;\n                cnt++;\n            }\n            \n           \n            while(cnt==2){\n                if(s.charAt(l)==ch){\n                    cnt--;                        \n                }\n                l++;\n            }\n        \n            \n            if(cnt==1){\n                result = (result + (prevChIndex + 1 - l)) % MOD;\n            }\n        }\n                \n        \n        return result;\n    }\n}\n```
[]