cs-014 — Course List Cleaner
| Field | Value |
|---|---|
| id | cs-014 |
| difficulty | Foundational |
| topics | python, sequences |
| lecture | lecture-04 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | lectures 1-2 (problem framing, precise pseudocode) |
| objective | recognise the pattern, translate it into precise steps, and trace it correctly |
| solution | held by the instructor; discussed after the attempt |
Problem
Given a list of course names with stray spaces and duplicates, produce a clean numbered list. Introduces list traversal and building output.
Your deliverable is the computed aggregates for the worked instance, the accumulator update rules, and one test input that breaks a careless initialisation. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: [" CS1 ", "DS1", "CS1", " Stats "]
- Output: 1. CS1 2. DS1 3. Stats (trimmed, deduplicated, numbered)
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- Build a new clean list while walking the old one; number from the clean list, not the raw one.
- Every aggregate here is a small machine: state + update rule.
- The initial value is part of the algorithm, not a detail.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Where exactly would this solution break first if the input grew to a million items — and would anything break at all?"
Constraints and assumptions
- Difficulty: Foundational (early-semester techniques assumed: precise statements, traces, simple loops).
- Topics: python, sequences.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes; naming the pattern and stating the assumption is already a pass, completing the calculation is the stretch.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Implement your pseudocode and verify it against your hand trace.