Implement encode/decode for list of strings
Company: NVIDIA
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Overview: This question evaluates a candidate's proficiency in string manipulation and serialization techniques, focusing on designing an invertible encode/decode scheme for lists of strings.
Constraints
- 0 <= number of strings <= 10^4
- The total number of characters across all input strings is at most 2 * 10^5
- Each original string may contain digits, spaces, and symbols, but it does not contain '#'
- For `decode`, the input string is guaranteed to be a valid encoding produced by the same scheme
Examples
Input: ("encode", ["foo", "lis", "jljl", "12345678901"])
Expected Output: "3foo#3lis#4jljl#1112345678901#"
Explanation: Each string is written as `<length><string>#`: `3foo#`, `3lis#`, `4jljl#`, and `1112345678901#`.
Input: ("decode", "3foo#3lis#4jljl#1112345678901#")
Expected Output: ["foo", "lis", "jljl", "12345678901"]
Explanation: Split at each `#`, then recover the length prefix inside each block.
Hints
- When decoding, first find the next `#`. Everything before it belongs to exactly one encoded block.
- If a block before `#` has total length `m`, and the length prefix has `d` digits, then the original string length must be `m - d`.