FastPrepLength-Prefixed String Codec
Problems/Length-Prefixed String Codec

Length-Prefixed String Codec

Snowflake logoSnowflake● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names the conventional encode-and-decode strings exercise. The explicit length-prefix format and combined finite adapter make the paired operations deterministic for practice; the judged core task matches at about 95%.

Encode a list of strings into one string and then decode it without loss.

Use the deterministic length-prefix format length#value for each input string, concatenated with no separator. Return an array whose first element is the encoded string and whose remaining elements are the strings obtained by decoding it.

Lengths are measured in characters. The character # and decimal digits may appear inside values.

Function

encodeAndDecodeStrings(strings: String[]) → String[]

Examples

Example 1

strings = ["lint","code"]return = ["4#lint4#code","lint","code"]

Each value is preceded by its character count and a hash delimiter.

Example 2

strings = ["","a#b","12"]return = ["0#3#a#b2#12","","a#b","12"]

Empty strings and delimiter characters remain unambiguous because decoding trusts the length.

Example 3

strings = []return = [""]

An empty list encodes to the empty string and decodes to no values.

Constraints

  • 0 <= strings.length <= 10000.
  • 0 <= strings[i].length <= 10000.
  • The total number of input characters is at most 200000.
  • Each string contains printable ASCII characters.

More Snowflake problems

  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public String[] encodeAndDecodeStrings(String[] strings) {
        // Write your solution here.
    }
}
Checking account…