C# Solution
I wanted to make sure that I post my solution, even though I could not complete it in the contest. \n\nThe idea is to find all the substrings where a character 
I wanted to make sure that I post my solution, even though I could not complete it in the contest. \n\nThe idea is to find all the substrings where a character occurs only once. So for every index of a character "A", we find out the number of substrings where there is possibly one and only instance of this character. This can be easily done by looking ahead and looking back for all the indices of "A" in the given string.\nFor e.g. For input string "ABCDAEFG", if we consider the character "A", this character\'s contribution to the sum will be 1 in all the substrings starting from index 0 till index 4 (excluding index 4 because there will be 2 A\'s in that substring "ABCDA").  Once we find such indices, the resulting sum for a character at a particular index i is calculated as follows:\n\n**int left =  no. of characters on the left side of the current index \nint right =  no. of characters on the right side of the current index \nproduct = left * right;\nsum = left + right + product + 1.**\n\n**product** because: if you have characters on the left and on the right, you can frame substrings that includes the current character.\n +1 because you can consider the current character standalone.\ne.g. substrings that include **one** instance of A at index 4 and contribute to the sum are \n**left = 3**\nBCDA\nCDA\nDA\n**right = 3**\nAEFG\nAEF\nAE\n**product = 9**\nBCDAE\nBCDAEF\nBCDAEFG\nCDAE\nCDAEF\nCDAEFG\nDAE\nDAEF\nDAEFG\n\n**Standalone A = 1** \n\nInput string : "ABCDAEFG"\nFor character A at index 4, left = 3 (you have B, C , D) and right = 3 (E, F, G) so its contribution will be 3 + 3 + (3 * 3) + 1.\nTime complexity is (26 * S.Length);\n\n```\n public int UniqueLetterString(string S) {\n        \n            if(string.IsNullOrEmpty(S)) return 0;\n            int MOD = 1000000007;\n            long res = 0;\n            for (int i = 0; i < 26; i++)\n            {\n                var cur = (char)(i + \'A\');\n                int last_index = -1;\n                int first_index = -1;\n                int second_index = -1;\n\n                first_index = S.IndexOf(cur);\n\n                if (first_index == -1) continue;\n\n                while (true)\n                {\n                    second_index = S.IndexOf(cur, first_index + 1);\n                    int left = first_index - (last_index + 1);\n                    int right = -1;\n\n                    if (second_index == -1)\n                        right = (S.Length - 1) - (first_index);\n                    else\n                        right = second_index - (first_index + 1);\n\n                    res += left;\n                    res += right;\n                    res++;\n                    res += (left * right);\n                    res %= MOD;\n                    if (second_index == -1) break;\n\n                    last_index = first_index;\n                    first_index = second_index;\n                    \n                }\n            }\n\n            return (int)res;\n    }\n```\n\n
[]