C# single pass
We keep 2 variables:\n- count\n- output\n\nCount represents the ongoing count we will add for each new char. Can think of this as the ongoing subarray count. Ou
We keep 2 variables:\n- count\n- output\n\nCount represents the ongoing count we will add for each new char. Can think of this as the ongoing subarray count. Output is the total output.\n\nWe keep track of the value added for every character so that if we see it again, we know how much of an impact this will have. If you think of the following string substrings:\n```\n1: ABCB\n2:  BCB\n3:   CB\n4:    B\n```\n\nWhen the final B is added, we want to know how much of our count gets skewed. In this case the ongoing count is deducted by 2 for the first 2 subarrays as when it was last added to `valueAddedByChar` it was at index 1(which makes the val 2). We then also know with the variable `unaffectedSubArrays` how many new characters we can add as we\'re at index 3(value 4) and the last time we saw this char was at index 1(value 2). In this case we can only add 2 as the value is only unique for subarray 3 and 4.\n\nWe can repeat this logic going on and keep adding count to the output to get the final number.\n\n```\npublic int UniqueLetterString(string s)\n{\n    int output = 0;\n    int count = 0;\n    int[] valueAddedByChar = new int[26];\n    var duplicateAt = new int[26];\n    Array.Fill(duplicateAt, -1);\n    for (var i = 0; i < s.Length; i++)\n    {\n        var currentChar = GetCharNum(s[i]);\n\n        // current index is a duplicate\n        if (duplicateAt[currentChar] != -1)\n        {\n            var lastSeen = duplicateAt[currentChar];\n            // Add previous indexes that were impacted by this char\n            // will now have 1 less val going forward\n            count -= valueAddedByChar[currentChar];\n            // All the subarrays that wont be impacted by the duplicate\n            var unaffectedSubArrays = (i - lastSeen);\n            valueAddedByChar[currentChar] = unaffectedSubArrays;\n            count += unaffectedSubArrays;\n        }\n        else\n        {\n            // cater for the 0-based numeric system by adding 1\n            valueAddedByChar[currentChar] = i + 1;\n            // Add a new num for ever subarray up to i as theyre all unique vals\n            count += valueAddedByChar[currentChar];\n        }\n        duplicateAt[currentChar] = i;\n        output += count;\n    }\n    return output;\n}\n\nprivate int GetCharNum(char c) => c - (int)\'A\';\n```
[]