Question
Count Substrings Without Duplicate Characters
You are given a string KaTeX can only parse string typed expression of length KaTeX can only parse string typed expression. Your task is to count the number of substrings of KaTeX can only parse string typed expression such that the substring does not contain any duplicate characters. In other words, every character in the substring must be unique.
A substring is defined as a contiguous sequence of characters within the string.
Input
The first line contains a single integer KaTeX can only parse string typed expression — the length of the string.
The second line contains a string KaTeX can only parse string typed expression consisting of lowercase English letters.
The second line contains a string KaTeX can only parse string typed expression consisting of lowercase English letters.
Output
Print a single integer — the number of substrings of KaTeX can only parse string typed expression that contain no duplicate characters.
Example
Example:
Input
5
abaca
Output
10
Explanation
Valid substrings with all unique characters:
a
b
a
c
a
ab
ba
bac
ac
ca
Total = 10 substrings.
Input
5
abaca
Output
10
Explanation
Valid substrings with all unique characters:
a
b
a
c
a
ab
ba
bac
ac
ca
Total = 10 substrings.