FastPrepString Compression
Problems/String Compression

String Compression

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Bloomberg new-grad phone-screen report names this well-known problem directly and mentions a corner case that was missed. The original exercise changes the array in place and returns the length of the compressed part. Here your function returns that compressed part as a string, so the result is easy to check in any language.

Given a string chars, compress each maximal run of equal consecutive characters.

  • Write the character once.
  • If the run length is greater than one, immediately follow it with the decimal digits of that length.

Return the complete compressed string. Run counts may contain multiple digits.

Function

compress(chars: String) → String

Examples

Example 1

chars = "aabbccc"return = "a2b2c3"

The consecutive runs have lengths 2, 2, and 3.

Example 2

chars = "a"return = "a"

A run of length one has no numeric suffix.

Example 3

chars = "abbbbbbbbbbbb"return = "ab12"

The first run has length one, and the twelve consecutive b characters use the two digits 12.

Constraints

  • 1 <= chars.length <= 100000.
  • chars contains printable ASCII characters other than line breaks.

More Bloomberg LP Phone Screen questions

  • 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
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Longest Palindromic SubstringSiemens · PHONE SCREEN
  • Shortest Deletion for Distinct CharactersOracle · ONSITE INTERVIEWOracle interview questions
  • Reverse Words in a StringAgoda · PHONE SCREENAgoda interview questions
  • Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
  • Word Collection: Distance and AnagramsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Shortest Way to Form a Target StringPinterest · PHONE SCREENPinterest interview questions
  • Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
  • Reverse File LinesCitadel · ONSITE INTERVIEWCitadel interview questions
  • Longest Palindromic Substring LengthMicrosoft · ONSITE INTERVIEWMicrosoft interview questions

Interview reports that mention this question

  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)

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
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String compress(String chars) {
        // Write your code here.
    }

}
Checking account…