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

@@ -28,6 +28,20 @@ sidebar:
- `1 <= s.length <= 2 * 10^5`
- `s` consists only of printable ASCII characters.
## Approach
```mermaid
flowchart TD
S(["isPalindrome(s)"]) --> N["normal = s stripped of non-alphanumerics, lowercased"]
N --> I["i = 0, j = normal.length - 1"]
I --> W{"i < j?"}
W -- no --> E(["return true — the pointers met in the middle"])
W -- yes --> Q{"normal[i] != normal[j]?"}
Q -- yes --> F(["return false"])
Q -- no --> A["i++; j-- — step both inward"]
A --> W
```
## Solution
```js
@@ -49,3 +63,7 @@ var isPalindrome = function(s) {
return true;
};
```
## Explanation
<YouTube id="jJXJ16kPFWg" title="Valid Palindrome - Leetcode 125 - Python" />
@@ -25,6 +25,18 @@ You must do this by modifying the input array in-place with O(1) extra memory.
- `1 <= s.length <= 10^5`
- `s[i]` is a printable ascii character.
## Approach
```mermaid
flowchart TD
S(["reverseString(s)"]) --> I["i = 0, j = s.length - 1"]
I --> W{"i < j?"}
W -- no --> E(["done — s was reversed in place, nothing returned"])
W -- yes --> A["swap s[i] and s[j]"]
A --> B["i++; j--"]
B --> W
```
## Solution
```js
@@ -43,3 +55,7 @@ var reverseString = function(s) {
}
};
```
## Explanation
<YouTube id="_d0T_2Lk2qA" title="Reverse String - 3 Ways - Leetcode 344 - Python" />
@@ -26,6 +26,22 @@ Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 10^9, and y
- `0 <= t.length <= 10^4`
- `s` and `t` consist only of lowercase English letters.
## Approach
```mermaid
flowchart TD
S(["isSubsequence(s, t)"]) --> G{"len(s) > len(t)?"}
G -- yes --> X(["return False"])
G -- no --> I["i = 0 into s, j = 0 into t"]
I --> W{"i < len(s) and j < len(t)?"}
W -- no --> E(["return i == len(s) — every char of s was matched"])
W -- yes --> Q{"s[i] == t[j]?"}
Q -- yes --> A["i += 1 — consume the match"]
Q -- no --> B["j += 1 — always advance t"]
A --> B
B --> W
```
## Solution
```py
@@ -42,3 +58,7 @@ class Solution:
return i == len(s)
```
## Explanation
<YouTube id="99RVfqklbCE" title="Is Subsequence - Leetcode 392" />