Longest Equal-Frequency Substring
Updated
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.
More DRW interview questions
- Defer Expenses to Preserve BalancePHONE SCREEN · Seen Oct 2026
- Minimize Range After Three ChangesPHONE SCREEN · Seen Oct 2026
- Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
- Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
- Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
- 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
- Nested In-Memory Database TransactionsOA · Seen Aug 2026
- Password Requirement CheckOA · Seen Aug 2026
- Remove Excess Consecutive CharactersOA · Seen Aug 2026
- Last Round for Each PlayerOA · Seen Jul 2026
Similar questions at other companies
- Weighted Next-Word Prediction From Training SequencesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Shortest Digit Prefix for Target MultisetsVisa · OAVisa interview questions
- Longest Balanced Substring After One SwapTekion · OATekion interview questions
- Count Special StringsAmazon · OA
- Longest Substring with Even OccurrencesDeloitte · OADeloitte interview questions
- Extraordinary SubstringsPalantir · OAPalantir interview questions
- Number of Divisible Substrings (For MLE)Wayfair · OAWayfair interview questions
- Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions