Longest Equal-Frequency Substring
Problem statement
You are given a lowercase English string s. A substring is balanced when every distinct letter that appears in it has the same frequency.
Return the maximum length of a balanced substring.
Function
longestBalancedSubstring(s: String) → intExamples
Example 1
s = "abbac"return = 4The substring abba contains two as and two bs.
Example 2
s = "aaaa"return = 4A substring containing only one distinct letter is balanced.
Example 3
s = "abcabc"return = 6Each of a, b, and c occurs twice.
Constraints
1 <= s.length <= 1000scontains only lowercase English letters.