FastPrepCount-First Run-Length Encoding
Problems/Count-First Run-Length Encoding

Count-First Run-Length Encoding

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the count-first example aabbcc -> 2a2b2c. We apply that rule to each longest run of the same letter. A run of one still shows its count, counts can have any number of digits, and an empty input gives an empty result. Source characters are lowercase English letters only.

Given a string text, encode each maximal run of equal consecutive characters from left to right.

For every run, append the run length in base 10 followed by the run's character. Include the count 1 for a singleton run. Return the concatenated encoding. Return the empty string when text is empty.

Function

runLengthEncode(text: String) → String

Examples

Example 1

text = "aabbcc"return = "2a2b2c"

Each of a, b, and c forms a run of length two.

Example 2

text = "aaabbcaaaaa"return = "3a2b1c5a"

The two separated runs of a are encoded independently, and the singleton c keeps count 1.

Example 3

text = ""return = ""

An empty input has no runs.

Constraints

  • 0 <= text.length <= 100000.
  • text contains only lowercase English letters.
  • Run lengths are written with all of their decimal digits.

More Bloomberg LP Phone Screen questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • English to Morse CodeOscar Health · PHONE SCREEN
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • Run-Length Encoding and DecodingAirbnb · PHONE SCREENAirbnb interview questions
  • Straight-Line Word SearchReddit · PHONE SCREENReddit interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Check if a String Is a PalindromeCisco · PHONE SCREENCisco interview questions
  • Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions

Interview reports that mention this question

  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad Screens: 30 Experiences (Part 4 of 5)
  • Bloomberg New Grad SWE Interviews: 98 Experiences (Part 1 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String runLengthEncode(String text) {
        // Write your code here.
    }

}
Checking account…