> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Visualizations

> TreeNode, ListNode, and GraphNode render as diagrams in Jupyter and clean ASCII in the terminal.

The data structure classes from `leetcode_py` convert between LeetCode's
array format and live objects, and render themselves so you can look at
what your code is doing.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from leetcode_py import GraphNode, ListNode, TreeNode
```

## Array format, live objects

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
root = TreeNode.from_list([3, 9, 20, None, None, 15, 7])
root.to_list()          # [3, 9, 20, None, None, 15, 7]

head = ListNode.from_list([1, 2, 3])
head.to_list()          # [1, 2, 3]

graph = GraphNode.from_adjacency_list([[2, 4], [1, 3], [2, 4], [1, 3]])
GraphNode.to_adjacency_list(graph)  # [[2, 4], [1, 3], [2, 4], [1, 3]]
```

Cyclic lists are safe: traversal detects cycles instead of hanging, in both
directions.

Each class carries a few extras beyond conversion and rendering:

* `TreeNode.find_node(value)` returns the first node with that value.
* `GraphNode.is_clone(other)` checks deep equality between a graph and its
  copy, the shape clone-graph problems ask for.
* All three are generic: `TreeNode[int]`, `ListNode[str]`, and so on.
* `from leetcode_py.data_structures import DictTree` gives a dict-backed
  tree that renders with box-drawing characters in the terminal and Graphviz
  in Jupyter, which suits Trie implementations.

## In Jupyter: diagrams

As the last expression of a cell, these objects render as Graphviz SVG
diagrams. `TreeNode` lays out top-to-bottom; `ListNode` goes left-to-right
with rounded boxes. A cyclic list draws the back-edge in red, dashed, and
labeled `cycle`.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
head = ListNode.from_list([1, 2, 3])
head.next.next.next = head.next   # cycle: 3 -> 2
head                              # renders the diagram, cycle included
```

![TreeNode rendered as a Graphviz tree diagram in Jupyter](https://mintcdn.com/leetcode-py/VCrzlUI648LnF7Pk/images/tree-viz.png?fit=max\&auto=format\&n=VCrzlUI648LnF7Pk\&q=85\&s=fbe45ad538379e80e6b9f31b0c217f11)

![ListNode rendered as a left-to-right box diagram in Jupyter](https://mintcdn.com/leetcode-py/VCrzlUI648LnF7Pk/images/linkedlist-viz.png?fit=max\&auto=format\&n=VCrzlUI648LnF7Pk\&q=85\&s=f0d3708eef0a004d929c993980abe7c3)

## In the terminal: ASCII

`print()` falls back to clean text: an indented tree, an arrow chain for
lists (cycles shown as `... (cycle back to 2)`), and a formatted adjacency
dict for graphs.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
print(root)
# 3
# ├── 9
# └── 20
#     ├── 15
#     └── 7
```

![TreeNode printed as an ASCII tree in the terminal](https://mintcdn.com/leetcode-py/VCrzlUI648LnF7Pk/images/tree-str-viz.png?fit=max\&auto=format\&n=VCrzlUI648LnF7Pk\&q=85\&s=781a3a70093cf73da7b7782975e9a3f5)

![ListNode printed as an arrow chain in the terminal](https://mintcdn.com/leetcode-py/VCrzlUI648LnF7Pk/images/linkedlist-str-viz.png?fit=max\&auto=format\&n=VCrzlUI648LnF7Pk\&q=85\&s=8ec66592d7bbc55e651c40fe4ab7dbb9)

## Requirements

Diagram rendering needs the system Graphviz binary (see
[Installation](https://leetcode-py.wisl.dev/getting-started/installation.md)). If it is missing, the
objects fall back to the ASCII form, so you get readable output either way.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.