docs(docs): add Approach diagrams and Explanation sections to LeetCode problem documentation

This commit is contained in:
Prad Nukala committed 2026-09-21 15:53:21 -04:00
1 parent b8c779903f
commit 23eb71d387
19 files changed
+439

No files matched your search

@@ -27,6 +27,27 @@ Could you write a generalized algorithm to work on any possible set of character
- `0 <= strs[i].length <= 200`
- `strs[i]` contains any possible characters out of 256 valid ASCII characters.
## Approach
::::warning
The diagram traces the code below literally. That code does not solve the problem: both `encode` and `decode` have only a docstring for a body, so each returns `None` and `codec.decode(codec.encode(strs))` yields `None` instead of `strs`.
::::
```mermaid
flowchart TD
subgraph state["state — Codec holds no fields"]
X["Codec() — nothing is stored between encode and decode"]
end
subgraph encode["encode(strs)"]
E1["docstring only — no statement runs"] --> E2(["return None"])
end
subgraph decode["decode(s)"]
D1["docstring only — no statement runs"] --> D2(["return None"])
end
state --> encode
state --> decode
```
## Solution
```py
@@ -46,3 +67,7 @@ class Codec:
# codec = Codec()
# codec.decode(codec.encode(strs))
```
## Explanation
<YouTube id="B1k_sxOSgv8" title="Encode and Decode Strings - Leetcode 271 - Python" />