Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    1781 - Sum of Beauty of All Substrings\.

    Medium

    The beauty of a string is the difference in frequencies between the most frequent and least frequent characters.

    • For example, the beauty of "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 <= 500

    • s consists of only lowercase English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer beautySum(String s)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait