docs(content): set meta display to page and improve interval documentation formatting

This commit is contained in:
Prad Nukala committed 2026-09-30 15:17:24 -04:00
1 parent 2ac54e9930
commit a7737502e1
3 files changed
+39 -37

No files matched your search

@@ -1,3 +1,8 @@
import { defineMeta } from "blume"; import { defineMeta } from "blume";
export default defineMeta({ title: "Binary Search", order: 5, icon: "search", display: "group" }); export default defineMeta({
title: "Binary Search",
order: 5,
icon: "search",
display: "page",
});
@@ -1,3 +1,8 @@
import { defineMeta } from "blume"; import { defineMeta } from "blume";
export default defineMeta({ title: "Hash Table", order: 1, icon: "hash", display: "group" }); export default defineMeta({
title: "Hash Table",
order: 1,
icon: "hash",
display: "page",
});
@@ -52,8 +52,13 @@ Sorting by start is the standard first line of almost every interval solution, a
That gives the template every interval problem in this section builds on: sort by start, then sweep once, comparing each interval against the last one you kept. That gives the template every interval problem in this section builds on: sort by start, then sweep once, comparing each interval against the last one you kept.
<Tabs> :::note[Input]
<Tab title="Example"> `[[1,3], [8,10], [2,6], [4,5], [10,12]]`
:::
:::note[After sort]
`[[1,3], [2,6], [4,5], [8,10], [10,12]]`
:::
```python ```python
# Time: O(n log n) # Time: O(n log n)
@@ -73,16 +78,7 @@ def interval_pattern(intervals):
return result return result
``` ```
</Tab> <Expandable title="Show trace table">
<Tab title="Trace">
:::note[Input]
`[[1,3], [8,10], [2,6], [4,5], [10,12]]`
:::
:::note[After sort]
`[[1,3], [2,6], [4,5], [8,10], [10,12]]`
:::
| i | `[start, end]` | `result[-1]` | `start <= result[-1][1]`? | Action | `result` after | | i | `[start, end]` | `result[-1]` | `start <= result[-1][1]`? | Action | `result` after |
|---|---|---|---|---|---| |---|---|---|---|---|---|
@@ -99,10 +95,10 @@ def interval_pattern(intervals):
- **Row 4:** `[8,10]` and `[10,12]` only touch at 10. The `<=` check merges them. With `<`, you would get two intervals. - **Row 4:** `[8,10]` and `[10,12]` only touch at 10. The `<=` check merges them. With `<`, you would get two intervals.
::: :::
</Tab> </Expandable>
</Tabs>
## Variant: Insert into a sorted list
## Insert into a sorted list
Sometimes the list is already sorted and has no overlaps, and you must add one new interval. You could append it, sort, and run the template. That works, but it pays `O(n log n)` for a sort you do not need. Sometimes the list is already sorted and has no overlaps, and you must add one new interval. You could append it, sort, and run the template. That works, but it pays `O(n log n)` for a sort you do not need.
@@ -114,17 +110,18 @@ A sorted list with no overlaps splits into three parts around the new interval,
Walk the list once and handle each part in turn. No sort, so the cost drops to `O(n)`. Walk the list once and handle each part in turn. No sort, so the cost drops to `O(n)`.
:::warning :::note[Intervals]
If the input is already sorted, do not sort again. Interviewers add "sorted" to the problem on purpose. Name the `O(n log n)` cost of re-sorting before they do, then offer the `O(n)` three-part walk. `[[1,2], [3,5], [6,7], [8,10], [12,16]]`
::: :::
<Tabs> :::note[New interval]
<Tab title="Example"> `[4,8]`
:::
```python ```python
# Time: O(n) # Time: O(n)
# Space: O(n) # Space: O(n)
def insert_interval(intervals, new_interval): def insert_interval(intervals, new_interval):
result = [] result = []
i, n = 0, len(intervals) i, n = 0, len(intervals)
start, end = new_interval start, end = new_interval
@@ -144,18 +141,10 @@ If the input is already sorted, do not sort again. Interviewers add "sorted" to
# 3. Starts after new ends: keep # 3. Starts after new ends: keep
result.extend(intervals[i:]) result.extend(intervals[i:])
return result return result
``` ```
</Tab> <Expandable title="Show trace table">
<Tab title="Trace">
:::note[Intervals]
`[[1,2], [3,5], [6,7], [8,10], [12,16]]`
:::
:::note[New interval]
`[4,8]`
:::
| i | interval | Part | Check | Action | `[start, end]` | `result` after | | i | interval | Part | Check | Action | `[start, end]` | `result` after |
|---|---|---|---|---|---|---| |---|---|---|---|---|---|---|
@@ -174,8 +163,11 @@ If the input is already sorted, do not sort again. Interviewers add "sorted" to
- **Part 1 uses `<`, part 2 uses `<=`:** An interval that ends exactly at `start` touches the new interval. It must fail part 1 so part 2 can merge it. - **Part 1 uses `<`, part 2 uses `<=`:** An interval that ends exactly at `start` touches the new interval. It must fail part 1 so part 2 can merge it.
::: :::
</Tab> </Expandable>
</Tabs>
:::warning
If the input is already sorted, do not sort again. Interviewers add "sorted" to the problem on purpose. Name the `O(n log n)` cost of re-sorting before they do, then offer the `O(n)` three-part walk.
:::
### Footnote ### Footnote