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

Encode and Decode a String Stream

Postman logoPostman● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Postman onsite interview. The report keeps the task as turning a stream of strings into tokens and back again, but it has no function signature. This exercise uses a protocol where each string has its length in front. It keeps the boundaries of any string. Our version is about 90% the same as the reported question.

Implement both directions of a length-prefixed string-stream protocol.

  • When operation is "ENCODE", encode values. Return a one-element array containing the encoded stream.
  • When operation is "DECODE", decode stream. Return the decoded strings and ignore values.

Each value is encoded as its decimal character length, followed by #, followed by its exact characters. Values may be empty and may themselves contain #, digits, spaces, or commas.

For DECODE, the stream is guaranteed to be a valid encoding produced by this protocol.

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"]

Lengths make the empty string and the embedded delimiter unambiguous.

Example 2

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

Reading the decimal length before each delimiter recovers every original boundary.

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 Postman interview questions

  • Group Duplicate Files by ContentONSITE INTERVIEW · Seen Feb 2026
  • Configuration SystemOA · Seen Sep 2020
  • Large ResponsesOA · Seen Sep 2020
  • Minimum Swaps to Sort an ArrayOA · Seen Aug 2020
  • Validate IP AddressOA · Seen Aug 2020
  • Without WhitespacesOA · Seen Sep 2019
  • Maximum Laptop Rating in a Price RangeOA · Seen Aug 2019

Similar questions at other companies

  • Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
  • Encode and Decode a String StreamHarness · ONSITE INTERVIEW
  • Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Encode and Decode a String StreamBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEWAirbnb interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
All Postman interview questionsSee Postman hiring insights
Saved
class Solution {
    public String[] transformStringStream(String operation, String[] values, String stream) {
        // write your code here
    }
}
Checking account…