From f2a2d2d7def9c5f3795c82c8912b468b7c6688ff Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Tue, 29 Sep 2026 17:15:21 -0400 Subject: [PATCH] docs(greedy): add Walk and Carry and Sort and Pick sections to Greedy Skeleton --- .../(05-decision-space)/greedy/index.mdx | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/apps/docs/content/(05-decision-space)/greedy/index.mdx b/apps/docs/content/(05-decision-space)/greedy/index.mdx index f616ca1..7d7ec2e 100644 --- a/apps/docs/content/(05-decision-space)/greedy/index.mdx +++ b/apps/docs/content/(05-decision-space)/greedy/index.mdx @@ -54,6 +54,30 @@ hidden: true ## The Greedy Skeleton +### Type 1: Walk and Carry + +:::info +No sort. Walk the list once. Carry one number. At each step, decide: keep it, or drop it. +::: + +```python +def walk_and_carry(nums): + carry = start_value + best = start_value + for n in nums: + if carry_is_useless(carry): + carry = fresh_start + carry = update(carry, n) + best = max(best, carry) + return best +``` + +### Type 2: Sort and Pick + +:::info +Used when order doesn't matter, so you pick the order. Meeting rooms, intervals, "most tasks by a deadline." +::: + ```python def greedy(items): # 1. Sort by the greedy key (deadline, end time, size, ratio, ...)