Reported May 2024
Postmanstring

Encode and Decode a String Stream

Reported by candidates from Postman's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Postman OA. Under 2s to a working solution.
Founder's read

Postman reported this one in May 2024, and the detail that matters is in the examples: "3#api0#3#a#b" has a # inside a value and an empty string, and the encoding still decodes cleanly. That's the whole problem. It's a length-prefixed string protocol with an ENCODE path and a DECODE path in one function. If you've seen the classic encode/decode strings problem, you're most of the way there. If not, the pattern is simple string parsing with a moving pointer. StealthCoder sits invisible on your screen as a safety net if you blank mid-assessment, but you should be able to walk in knowing this.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that you never search for a delimiter blindly. For ENCODE, append the length, then #, then the raw string for each value, and return a one-element array. Use a list and join once, not repeated concatenation, because the input can hit 10^6 characters. For DECODE, keep an index i. Scan forward to the next #, parse the digits before it as length n, then slice exactly n characters after the #. Move i to the end of that slice and repeat. The common pitfall is splitting on # or searching for the last one, which breaks when a value contains # or digits. Another is mishandling length 0, where you should output an empty string and advance past the #. Also remember DECODE ignores values and ENCODE ignores stream. If you freeze on the pointer math during the live OA, StealthCoder is the hedge that gives you the loop.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Encode and Decode a String Stream cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as encode and decode strings. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Postman's OA.

Postman reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Encode and Decode a String Stream FAQ

How hard is the Postman Encode and Decode a String Stream problem really?+

Easy to medium. The logic is short, but it punishes sloppy parsing. If you know length-prefix encoding, you can write it in ten minutes. The difficulty is handling empty strings and values that contain # or digits without breaking the boundaries.

What's the trick to decoding without ambiguity?+

Read digits up to the first # from your current position, convert them to an integer n, then take exactly n characters after that #. Never scan for the next # inside the payload. The length tells you where the value ends, so embedded delimiters don't matter.

Why does the example with a#b still decode correctly?+

Because the encoder writes 3#a#b, and the decoder reads 3 as the length, skips the first #, then grabs exactly three characters: a, #, b. The extra # sits inside the counted payload, so it never gets treated as a delimiter.

What complexity should I aim for given 10^6 characters?+

Linear time, O(total characters). Build the output with a list or string builder and join once. Avoid slicing the remaining stream repeatedly or concatenating in a loop, since that can turn into quadratic behavior on large inputs.

How do I prepare for this in 48 hours?+

Write the encoder and decoder from scratch twice. Test with an empty string, a value containing #, a value made of digits, and a multi-digit length like 12. Also test an empty values array for ENCODE and an empty stream for DECODE.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Postman.

OA at Postman?
Invisible during screen share
Get it