docs(docs): add Approach and Explanation sections with mermaid diagrams to problem pages

This commit is contained in:
Prad Nukala committed 2026-09-01 14:21:54 -04:00
1 parent e59d78e571
commit a86d72c7db
43 files changed
+812

No files matched your search

+18
View File
@@ -32,6 +32,20 @@ Can you come up with an algorithm that is less than O(n^2) time complexity?
- `-10^9 <= target <= 10^9`
- Only one valid answer exists.
## Approach
```mermaid
flowchart TD
S(["twoSum(nums, target)"]) --> I["seen = {} — value to index"]
I --> L{"more (i, num) in nums?"}
L -- no --> E(["return []"])
L -- yes --> C["complement = target - num"]
C --> H{"complement in seen?"}
H -- yes --> R(["return [seen[complement], i]"])
H -- no --> W["seen[num] = i"]
W --> L
```
## Solution
```py
@@ -45,3 +59,7 @@ class Solution:
seen[num] = i
return []
```
## Explanation
<YouTube id="KLlXCFG5TnA" title="Two Sum - Leetcode 1 - HashMap - Python" />