Kotlin Best Solution
\n# Code\n\nclass Solution {\n    fun uniqueLetterString(s: String): Int {\n        val previousStore = IntArray(28)\n        val beforePreviousStore = IntArray
\n# Code\n```\nclass Solution {\n    fun uniqueLetterString(s: String): Int {\n        val previousStore = IntArray(28)\n        val beforePreviousStore = IntArray(28)\n        \n        val dp = IntArray(s.length + 1)\n        var sum = 0\n        for (i in 1 .. s.length) {\n            var ch = s[i-1]\n            dp[i] = dp[i-1] + i\n            \n            val previous = previousStore[ch - \'A\']\n            val beforePrevious = beforePreviousStore[ch - \'A\']\n            \n            dp[i] -= previous * 2 - beforePrevious\n            \n            beforePreviousStore[ch - \'A\'] = previous\n            previousStore[ch - \'A\'] = i\n            \n            sum += dp[i]\n        }\n        return sum\n    }\n}\n```
['Kotlin']