Practice: Permutations
Problem: https://leetcode.com/problems/permutations/
Recognition reminder: you are asked to generate every ordering of the input. “Generate all permutations” is the backtracking cue. This is the contrast with Subsets: here order matters, so [1, 2] and [2, 1] are two different answers, and a start index would wrongly throw half of them away. Track which elements are already used instead.
Before you start (the five-beat rhythm)
- Your Pattern Card for this week is already written.
- Name the pattern aloud and write your approach as a plain-English comment before any code.
- Struggle floor: 25 minutes unaided. No hints, no AI, no Discuss tab.
- If stuck past the floor, ask the tutor for a hint. Six rungs, one per ask.
- Debrief in your commit message before moving to the next problem.
Your target
Fill these in yourself before you look at anyone else’s solution:
Target time complexity: ____
Target space complexity: ____
There are n! permutations of n distinct elements, and each is length n. Let that set your time target. Ask yourself what bookkeeping tells a recursive call which elements are still available, and why a start index (the Subsets trick) is the wrong tool here.
Where your code goes
Write your solution in your own work repo (see getting-started.md), not in this folder. This folder ships only the problem spec and a provided-example test (tests/test_provided.py) so you can check the given cases locally before you submit to LeetCode’s judge. The judge is the oracle; the tutor will not confirm your answer by reading it.
Note on the test: the permutations may be returned in any order, so the provided test sorts the outer list before comparing. The order inside each permutation is meaningful (that is the whole point of a permutation), so the test does not touch it: it compares each permutation as an exact ordered sequence.
Debrief (paste into your commit message)
1. What pattern did this turn out to be?
2. What was the trigger phrase or input shape that should have made me reach for it?
3. What was the time and space complexity, and what would dominate at scale?
4. What edge case would have broken my first attempt?
5. What would I do differently in three days when I see this cold?