The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.
"abaacc" is 3 - 1 = 2.Given a string s, return the sum of beauty of all of its substrings.
Example 1:
Input: s = "aabcb" Output: 5 Explanation: The substrings with non-zero beauty are ["aab","aabc","aabcb","abcb","bcb"], each with beauty equal to 1.
Example 2:
Input: s = "aabcbaa" Output: 17
Constraints:
1 <= s.length <= 500s consists of only lowercase English letters.Solutions for this problem are being prepared.
Try solving it yourself❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD • Striver • 522,271 views views
Watch 9 more video solutions →Practice Sum of Beauty of All Substrings with our built-in code editor and test cases.
Practice on FleetCode