Encode and Decode Strings

Medium
StringDesignPremiumGoogleMeta
Design a reversible string codec using the format `length#value` for each string. Input format: - First line: n - Next n lines: one raw string per line. Strings may contain spaces and `#`, but not newlines. Encode the list, decode the encoded payload, then print the encoded payload on the first line and the decoded strings on the following n lines.

Constraints

1 <= n <= 10^4
0 <= string length <= 10^4
Total input characters <= 2 * 10^5

Sample tests

Sample 1

Sample 2

Sign in to submit