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

@@ -31,6 +31,16 @@ Your algorithm's time complexity must be better than O(n log n), where n is the
- `k` is in the range `[1, the number of unique elements in the array]`.
- It is guaranteed that the answer is unique.
## Approach
```mermaid
flowchart TD
S(["topKFrequent(nums, k)"]) --> F["freq: count every value in nums"]
F --> K["keys of freq, cast to Number"]
K --> O["sort by freq[b] - freq[a] — most frequent first"]
O --> R(["return slice(0, k)"])
```
## Solution
```js
@@ -49,3 +59,7 @@ var topKFrequent = function (nums, k) {
.slice(0, k);
};
```
## Explanation
<YouTube id="YPTqKIgVk-k" title="Top K Frequent Elements - Bucket Sort - Leetcode 347 - Python" />