FastPrepLongest Equal-Frequency Substring
Problems/Longest Equal-Frequency Substring

Longest Equal-Frequency Substring

DRW logoDRW● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report calls a substring balanced when every letter that appears in it appears the same number of times. Our version is about 99% the same as the reported question.

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) → int

Examples

Example 1

s = "abbac"return = 4

The substring abba contains two as and two bs.

Example 2

s = "aaaa"return = 4

A substring containing only one distinct letter is balanced.

Example 3

s = "abcabc"return = 6

Each of a, b, and c occurs twice.

Constraints

  • 1 <= s.length <= 1000
  • s contains 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
All DRW interview questionsSee DRW hiring insights
Saved
class Solution {
    public int longestBalancedSubstring(String s) {
        // Write your code here.
    }

}
Checking account…