2022-03-27 18:27:43 +08:00
< p > The < strong > beauty< / strong > of a string is the difference in frequencies between the most frequent and least frequent characters.< / p >
< ul >
< li > For example, the beauty of < code > " abaacc" < / code > is < code > 3 - 1 = 2< / code > .< / li >
< / ul >
< p > Given a string < code > s< / code > , return < em > the sum of < strong > beauty< / strong > of all of its substrings.< / em > < / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 18:27:43 +08:00
< pre >
< strong > Input:< / strong > s = " aabcb"
< strong > Output:< / strong > 5
< strong > Explanation: < / strong > The substrings with non-zero beauty are [" aab" ," aabc" ," aabcb" ," abcb" ," bcb" ], each with beauty equal to 1.< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 18:27:43 +08:00
< pre >
< strong > Input:< / strong > s = " aabcbaa"
< strong > Output:< / strong > 17
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = s.length < =< sup > < / sup > 500< / code > < / li >
< li > < code > s< / code > consists of only lowercase English letters.< / li >
< / ul >