count unique characters in substrings

Given a string S, you need to count all the unique characters for substrings of the given string.

Example:

S='aabb'

output=14

a 1
aa 1
aab 2
aabb 2
a 1
ab 2
abb 2
b 1
bb 1
b 1

S="abc"
output=10

Expected time complexity O(n)

Comments (3)