From a7737502e1c266a08a5ddeb03857f6eace0c1074 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Wed, 30 Sep 2026 15:17:24 -0400 Subject: [PATCH] docs(content): set meta display to page and improve interval documentation formatting --- .../binary-search/meta.ts | 7 +- .../(01-linear-structures)/hash-table/meta.ts | 7 +- .../(05-decision-space)/intervals/index.mdx | 94 +++++++++---------- 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/apps/docs/content/(01-linear-structures)/binary-search/meta.ts b/apps/docs/content/(01-linear-structures)/binary-search/meta.ts index dfb9611..bf1a931 100644 --- a/apps/docs/content/(01-linear-structures)/binary-search/meta.ts +++ b/apps/docs/content/(01-linear-structures)/binary-search/meta.ts @@ -1,3 +1,8 @@ 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", +}); diff --git a/apps/docs/content/(01-linear-structures)/hash-table/meta.ts b/apps/docs/content/(01-linear-structures)/hash-table/meta.ts index 6a323fe..768b28e 100644 --- a/apps/docs/content/(01-linear-structures)/hash-table/meta.ts +++ b/apps/docs/content/(01-linear-structures)/hash-table/meta.ts @@ -1,3 +1,8 @@ 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", +}); diff --git a/apps/docs/content/(05-decision-space)/intervals/index.mdx b/apps/docs/content/(05-decision-space)/intervals/index.mdx index 9701b23..b7eb845 100644 --- a/apps/docs/content/(05-decision-space)/intervals/index.mdx +++ b/apps/docs/content/(05-decision-space)/intervals/index.mdx @@ -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. - - +:::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]]` +::: ```python # Time: O(n log n) @@ -73,16 +78,7 @@ def interval_pattern(intervals): return result ``` - - - - :::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 | |---|---|---|---|---|---| @@ -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. ::: - - + -## 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. @@ -114,48 +110,41 @@ 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)`. -:::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. +:::note[Intervals] +`[[1,2], [3,5], [6,7], [8,10], [12,16]]` ::: - - +:::note[New interval] +`[4,8]` +::: - ```python - # Time: O(n) - # Space: O(n) - def insert_interval(intervals, new_interval): - result = [] - i, n = 0, len(intervals) - start, end = new_interval +```python +# Time: O(n) +# Space: O(n) +def insert_interval(intervals, new_interval): + result = [] + i, n = 0, len(intervals) + start, end = new_interval - # 1. Ends before new starts: keep - while i < n and intervals[i][1] < start: - result.append(intervals[i]) - i += 1 + # 1. Ends before new starts: keep + while i < n and intervals[i][1] < start: + result.append(intervals[i]) + i += 1 - # 2. Overlaps new: grow new to cover it - while i < n and intervals[i][0] <= end: - start = min(start, intervals[i][0]) - end = max(end, intervals[i][1]) - i += 1 - result.append([start, end]) + # 2. Overlaps new: grow new to cover it + while i < n and intervals[i][0] <= end: + start = min(start, intervals[i][0]) + end = max(end, intervals[i][1]) + i += 1 + result.append([start, end]) - # 3. Starts after new ends: keep - result.extend(intervals[i:]) - return result - ``` + # 3. Starts after new ends: keep + result.extend(intervals[i:]) + return result +``` - - + - :::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 | |---|---|---|---|---|---|---| @@ -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. ::: - - + + +:::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