FastPrepThresholded Run-Length Encoding
Problems/Thresholded Run-Length Encoding

Thresholded Run-Length Encoding

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Our version is about 92% the same as the reported question. The Bloomberg new-grad virtual-onsite report gives the encoding rule with a threshold of three, the separator, an example, and a follow-up about data split across machines. We chose the lowercase alphabet and the input limit so the problem can be checked.

You are given a nonempty lowercase string s. Process each maximal run of equal consecutive characters independently.

If a run contains at least three copies of its character, replace the entire run with the character, followed by #, followed by the run length. Leave runs of length one or two unchanged.

Return the encoded string.

After implementing the function, explain how independently processed contiguous chunks can be merged correctly when a run crosses a worker boundary.

Function

encodeLongRuns(s: String) → String

Examples

Example 1

s = "dddjjwaaaa"return = "d#3jjwa#4"

The three d characters and four a characters are encoded; the shorter runs stay unchanged.

Example 2

s = "aabbbcc"return = "aab#3cc"

Only the run of three b characters reaches the encoding threshold.

Example 3

s = "abcdef"return = "abcdef"

Every run has length one, so the string is unchanged.

Constraints

  • 1 <= s.length <= 100000.
  • s contains only lowercase English letters.

More Bloomberg LP Onsite Interview 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
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Alternate String EndsCapital One · OACapital One interview questions
  • Concatenate Digit-wise SumsZipRecruiter · OAZipRecruiter interview questions
  • Reverse First K Characters in Every 2K BlockArcesium · OAArcesium interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
  • Format TextTikTok · OATikTok interview questions
  • String CompressionShnoor International · ONSITE INTERVIEW
  • Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
  • Christmas Tree with N TiersVerily · ONSITE INTERVIEW
  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions

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)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String encodeLongRuns(String s) {
        // Write your code here.
    }

}
Checking account…