VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 02: Hashing

Lesson 2.10 of 12 in this module Unrolled Pro

Encode and Decode Strings

Pack a list of arbitrary strings into one string and get exactly the same list back: why delimiters break, how escaping fixes them, and why a length prefix needs no scanning at all. Then binary length headers, streaming decoders and how real dataset formats store text records.

about 10 min 5 Python examples 2 quick checks

Problem. Design encode(strs) -> str and decode(s) -> list[str] so that decode(encode(strs)) == strs for any list of strings, including empty strings and strings containing any character.

text
["hello", "world"]   →  encode  →  some string  →  decode  →  ["hello", "world"]
["a,b", "", "#3"]    →  …must also round-trip exactly

ML context. Every dataset of text has to be stored somehow: training shards, tokenised corpora, logged prompts. Formats like length-prefixed record files exist precisely because the naive approach (one record per line, or comma-separated) breaks the moment a record contains a newline or a comma. This lesson is the core of serialisation: making boundaries unambiguous.

This isn't about hashing directly; it's here because it's the classic "design a format" problem, and the length prefix is the same "store a small header so you never have to search" idea behind hash tables' O(1) jumps.


1. Step 1: Clarify

The empty list vs [""] case is a good test of any design: both must encode differently.

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Encode and Decode Strings"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee