Longest Balanced Substring II
You receive a string s consisting only of the characters 'a' , 'b' , and 'c' .
A substring of s is called balanced if all distinct characters in the substring appear the same count of times.
Produce the length of the longest balanced substring of s .
Input: s = "abbac"
Output: 4
Explanation: For this case, the longest balanced substring is "abba" because both distinct characters 'a' and 'b' each appear exactly 2 times.
Input: s = "aabcc"
Output: 3
Explanation: For this case, the longest balanced substring is "abc" because all distinct characters 'a' , 'b' and 'c' each appear exactly 1 time.
Input: s = "aba"
Output: 2
Explanation: For this case, one of the longest balanced substrings is "ab" because both distinct characters 'a' and 'b' each appear exactly 1 time. Another longest balanced substring is "ba" .
Constraints
1 <= s.length <= 10^5scontains only the characters'a','b', and'c'.
Did this problem appear in one of your interviews?
Responses stay private.
