# Serialize and deserialize a list of strings | Aced

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/1307/serialize-deserialize-list-strings
Source observed: 2026-11-05T00:27:44.741Z
Last checked: 2026-11-05T00:27:44.741+00:00
Indexed: 2026-11-07T03:52:22.736+00:00

---

# Write functions to serialize and deserialize a list of strings

**Difficulty:** Medium  
**Category:** [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms) and [Coding](https://www.aced.io/questions?type=coding)  
**Role:** [Software Engineer](https://www.aced.io/questions?role=swe)  
**Companies:** [Nvidia](https://www.aced.io/questions?company=nvidia), [Google](https://www.aced.io/questions?company=google)  
**Reported last asked:** 2 years ago  
**Interview count:** 2

We ask you to write two functions, `serialize` and `deserialize`, for a list of strings. `serialize` accepts a list and returns one string; `deserialize` accepts that string and reconstructs the original list.

## Requirements

- `serialize` concatenates the strings into one string.
- Each original string's length is encoded as a character prefix immediately before that string.
- `deserialize` uses those encoded lengths to split the combined string back into the original strings.
- Assume every string contains ASCII characters only.

For example, `["hello", "world"]` can serialize as `"\\x05hello\\x05world"`, where `\\x05` indicates that the following string has length 5.

## Constraints and edge cases

- The maximum length of any string is `65535` (`0xFFFF`).
- `serialize` must raise an exception if a string exceeds that maximum.
- `deserialize` must handle empty strings and single-character strings accurately.

## Examples

```text
lst = ['hello', 'world']
serialized = serialize(lst)       # "\\x05hello\\x05world"
deserialized = deserialize(serialized)  # ['hello', 'world']

lst = ['']
serialized = serialize(lst)        # "\\x00"
deserialized = deserialize(serialized)  # ['']

lst = ['a', 'bc', 'def']
serialized = serialize(lst)        # "\\x01a\\x02bc\\x03def"
deserialized = deserialize(serialized)  # ['a', 'bc', 'def']
```

No community answers have been contributed yet. The question includes **Question**, **Solution**, **Mock Interview**, and **Community** views; the community tab displays 11.

## Related questions

- [Write a function to do Excel-style operations.](https://www.aced.io/questions/5823/function-to-do-excel-style-operations)
- [Write a function to check whether a string contains a substring.](https://www.aced.io/questions/4621/check-substring-in-string)
- [Given a list of bounding boxes and annotations, write a function to compute Intersection over Union.](https://www.aced.io/questions/6596/compute-intersection-over-union-bounding-boxes)

## Related courses

### [Software Engineering Interview Prep](https://www.aced.io/courses/software-engineering)

We help candidates prepare for software engineering roles at Google, Amazon, Microsoft, Meta, Apple, and other top companies through mock interviews, frameworks, and advice from senior candidates. Topics include data structures, algorithms, system design, people management, behavioral interviews, and more.

![Software Engineering Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/4VkuYewBHUFIVUS5oJDW5h/02e833439b1289f25f38f13f81cbdca3/adobe_stock_optimized.jpeg?w=800&h=800&fm=webp&q=75)

### [System Design Interviews](https://www.aced.io/courses/system-design-interviews)

We teach candidates to answer current system design questions across product, infrastructure, and AI domains with in-depth video examples, written breakdowns, reference patterns, and mock interview videos featuring senior engineers and managers.

![System Design Interviews](https://images.ctfassets.net/x78yjrjc11pq/78x7miFZFjBCrM5GqftrMJ/2f6d26e632c4e7265c49f6a180227edb/system_design_track_compressed_26ac98a46e__281_29_5be2280f31.jpeg?w=800&h=800&fm=webp&q=75)

## Practice access

You can [sign up to run code](https://www.aced.io/signup?src=lesson). Detailed company statistics are available through [Upgrade](https://www.aced.io/upgrade?src=questions).

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F1307%2Fserialize-deserialize-list-strings&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F1307%2Fserialize-deserialize-list-strings). Opening a form does not execute a tool.