Search
⌘K

Leetcode 1781. Sum of Beauty of All Substrings

Compute the sum, over all substrings of s (n ≤ 500), of the "beauty" defined as the difference between the most frequent and least frequent characters that appear in the substring. The key challenge is enumerating substrings while maintaining character counts to efficiently compute max/min nonzero frequencies (typical solutions use O(n^2 · 26) counting).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.