Encode and Decode a String Stream
Updated
Problem statement
Given operation, values and stream, return either the encoded form of values or the strings decoded from stream.
- When
operationis"ENCODE", encodevalues. Return a one-element array holding the encoded stream. - When
operationis"DECODE", decodestreamand return the strings. Ignorevalues.
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
operationis eitherENCODEorDECODE.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,streamis 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)