A curated collection of LeetCode solutions built for understanding, revision, and reuse.
Browse by Topic | Browse by Difficulty | Architecture | Solution Standard
This repository preserves more than accepted code. Each solution records:
| Pattern | Reasoning | Implementation |
|---|---|---|
| The ideas involved | The invariant that makes them work | The trade-offs shaping the final code |
Many LeetCode problems belong to several topics at once. A problem might combine graphs, heaps, and greedy reasoning, while still having only one implementation.
That leads to the central design rule:
Store every solution once. Reference it from every topic and difficulty where it belongs.
The physical files are organized by problem ID. The indexes provide different views of the same archive without duplicating solutions.
| View | Best used for | Open |
|---|---|---|
| Topics | Studying patterns and related techniques | Explore topics |
| Difficulty | Choosing an appropriate challenge level | Explore difficulties |
| Problem ID | Finding a known problem quickly | Explore solutions |
For example, 0003-longest-substring-without-repeating-characters.cpp exists once under solutions/0001-0500/, but can appear under Hash Table, String, Sliding Window, and Medium in the indexes.
LeetCode-Solutions/
+-- solutions/
| +-- 0001-0500/
| | +-- 0003-longest-substring-without-repeating-characters.cpp
| +-- 0501-1000/
| +-- 1001-1500/
| +-- 1501-2000/
| +-- ...
+-- indexes/
| +-- topics.md
| +-- difficulty.md
+-- templates/
| +-- solution.cpp
+-- README.md
| Decision | Reason |
|---|---|
| Store by ID range | Every problem has one obvious, permanent location |
| Index by multiple topics | A solution can belong to every relevant technique |
| Index by difficulty | Difficulty remains browsable without controlling storage |
| Never duplicate solution files | Improvements happen in one place and links remain consistent |
Difficulty subfolders are intentionally avoided. A structure such as Medium/Graphs/ still fails when a problem has multiple topics and encourages duplicate files.
flowchart LR
S["One solution file"] --> T1["Topic: Sliding Window"]
S --> T2["Topic: Hash Table"]
S --> T3["Topic: String"]
S --> D["Difficulty: Medium"]
style S fill:#082f49,stroke:#00C9FF,color:#ffffff
style T1 fill:#083344,stroke:#22d3ee,color:#ffffff
style T2 fill:#064e3b,stroke:#5eead4,color:#ffffff
style T3 fill:#14532d,stroke:#86efac,color:#ffffff
style D fill:#365314,stroke:#92FE9D,color:#ffffff
The primary insight explains the main breakthrough. The topics field captures every relevant classification.
Every solution should remain useful after the original problem is no longer fresh.
/*
* Problem: 0003. Longest Substring Without Repeating Characters
* Link: https://leetcode.com/problems/longest-substring-without-repeating-characters/
* Difficulty: Medium
* Primary insight: Sliding Window
* Topics: Hash Table, String, Sliding Window
* Time: O(n)
* Space: O(k)
*
* Insight:
* Maintain a window containing no repeated characters.
*/| Principle | What it means here |
|---|---|
| One canonical solution | Keep exactly one implementation of each problem |
| Multiple classifications | Link that implementation from every relevant index section |
| Reasoning over narration | Comments explain decisions and invariants, not obvious syntax |
| Explicit complexity | Time and space costs remain visible during revision |
flowchart LR
A["Read constraints"] --> B["Recognize patterns"]
B --> C["Define the invariant"]
C --> D["Implement clearly"]
D --> E["Review trade-offs"]
E -. "refine" .-> B
style A fill:#082f49,stroke:#00C9FF,color:#ffffff
style B fill:#083344,stroke:#22d3ee,color:#ffffff
style C fill:#064e3b,stroke:#5eead4,color:#ffffff
style D fill:#14532d,stroke:#86efac,color:#ffffff
style E fill:#365314,stroke:#92FE9D,color:#ffffff
The goal is not to force each problem into one category. It is to understand how several techniques cooperate inside one solution.
Solutions are written primarily in modern C++, with an emphasis on standard-library fluency, explicit complexity, and interview-ready reasoning.
- Problem statements and examples belong to LeetCode.
- Solutions are personal implementations created for learning and reference.
- Indexes are navigation layers, not progress trackers.