Skip to content

Practice Sum of Beauty of All Substrings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1781
LeetCode Problem

Sum of Beauty of All Substrings

Problem Statement

The beauty of a string is the difference in frequencies between the most frequent and least frequent characters. Given a string s, return the sum of beauty of all of its substrings.

Source: Sum of Beauty of All Substrings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aabcb"
Output
5

# Example 2

Input
s = "aabcbaa"
Output
17

Constraints

1 <= s.length <= 500
s consists of only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Sum of Beauty of All Substrings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.