Count-First Run-Length Encoding
Updated
Problem statement
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) → StringExamples
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.textcontains 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