Case-based lecture: you attempt, we discuss, then we reveal.
cs-033, cs-142, cs-034, cs-035, cs-036Pages [12, 0, 25, 8, 30], target 10. Report total, average, best day, and how many days fell below target.
Expected: {'total': 75, 'avg': 15.0, 'best': 30, 'below': 2}
Cost: O(n) time, O(1) space - four aggregates for the price of one loop.
Sales [100, 210, 205, 420, 90]. A day is a spike if it beats both neighbours. Reference answer: [1, 3].
Expected: [1, 3]
Cost: O(n) time, O(1) extra space (output excluded).
Goals met [1, 1, 0, 1, 1, 1, 0, 1]. Longest streak of consecutive met goals - plus two zero cases: end-on-a-miss, and all-miss.
Expected: best 3 | end-current 0 in the reference's variant | all-miss 0
Cost: O(n) time, O(1) space - the two-variable discipline is the whole lesson.
Rain [3, 5, 2, 8, 1, 4], window k = 3. The reference prints [5, 8, 8, 8] - derive what question it actually answers before trusting the prose.
pages = [12, 0, 25, 8, 30]
target = 10
total = sum(pages)
best = max(pages)
below = sum(1 for p in pages if p < target)
print(total, total / len(pages), best, below)Expected: sums [10, 15, 11, 13]; maxima [5, 8, 8, 8] (the reference's question)
Cost: O(n) slide vs O(n*k) recomputed - the analysis teaser for Block III.
From a list of daily page counts, output total, average, best day, and days below target. The canonical running-total lecture case.
**Input:** pages [12, 0, 25, 8, 30], target 10**Output:** total 75, average 15.0, best 30, below-target days 3 (0, 8, and... recount: 0,8 yes; 12 no; careful)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-033 — not embedded in this deck.
Eleven committee members each wrote one name on a slip:
**Input:** the eleven slips**Output:** Zoe 4, Amir 3, Bea 2, Cal 2 — winner Zoe 36.4%,runner-up Amir 27.3% — one honest sentenceSolve for the worked instance first. Then ask what would change if onePseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-142 — not embedded in this deck.
Find days when sales exceeded double the previous day's sales. Combines aggregation with a 'look at the previous element' pattern.
**Input:** sales [100, 210, 205, 420, 90]**Output:** spike days: index 1 (210 > 2x100) and index 3 (420 > 2x205); not index 2 (205 < 2x210)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-034 — not embedded in this deck.
Count the longest run of consecutive goals met in a habit tracker. Two-level state: current streak vs best streak, and resetting correctly.
**Input:** goals met: [1, 1, 0, 1, 1, 1, 0, 1]**Output:** current best streak 3 (days 4-6); final streak at end is 1 - do not confuse the twoSolve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-035 — not embedded in this deck.
For a window of the last k days, report the running maximum without re-summing the whole window each time. A gentle sliding-window preview.
**Input:** rain [3, 5, 2, 8, 1, 4], window k = 3**Output:** window maxima: 5, 8, 8, 8 (windows [3,5,2], [5,2,8], [2,8,1]... recheck: [2,8,1] -> 8, [8,1,4] -> 8)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-036 — not embedded in this deck.