FastPrepEncode and Decode a String Stream
Problems/Encode and Decode a String Stream

Encode and Decode a String Stream

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Bloomberg New Grad report 924496 identifies Encode and Decode Strings and its arbitrary-character follow-up. The operation wrapper exposes both directions through one judgeable call and matches the reported exercise at about 95%.

Given operation, values and stream, return either the encoded form of values or the strings decoded from stream.

  • When operation is "ENCODE", encode values. Return a one-element array holding the encoded stream.
  • When operation is "DECODE", decode stream and return the strings. Ignore values.

The encoded stream is the values written one after another. Each value is written as its length in characters (in decimal), then #, then the value itself. Values may be empty and may contain #, digits, spaces, or commas.

For DECODE, the stream is always a valid encoding made this way.

Function

transformStringStream(operation: String, values: String[], stream: String) → String[]

Examples

Example 1

operation = "ENCODE"values = ["api","","a#b"]stream = ""return = ["3#api0#3#a#b"]

Each value is written as its length, then #, then the value. Because the length comes first, the empty string and the # inside a#b cause no confusion.

Example 2

operation = "DECODE"values = []stream = "5#hello5#world0#"return = ["hello","world",""]

Read the length before each #, then take that many characters. This gives hello, world, and an empty string at the end.

Constraints

  • operation is either ENCODE or DECODE.
  • 0 ≤ values.length ≤ 10^5
  • Strings contain printable ASCII characters.
  • The total number of characters in the relevant input is at most 10^6.
  • For DECODE, stream is valid.

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

  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
  • Encode and Decode a String StreamHarness · ONSITE INTERVIEW
  • Encode and Decode a String StreamPostman · ONSITE INTERVIEWPostman interview questions
  • Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI 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[] transformStringStream(String operation, String[] values, String stream) {
        // write your code here
    }
}
Checking account…