Thresholded Run-Length Encoding
Updated
Problem statement
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) → StringExamples
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.scontains 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)