Restate the problem in your own words
standardbeginnerBefore writing any code, turn the prompt into a precise contract: exact inputs, exact output, and what happens on ties or missing matches. A vague restatement hides decisions you will otherwise make by accident while coding.
Think of it as
A vague prompt is a contract with blank clauses. 'Find two prices that add up to a budget' does not say what to return if several pairs work, what to return if none do, or whether the same price can be used twice. Restating the problem means filling in every blank BEFORE you write a line of code, so the function's behavior is a decision you made on purpose, not one the code happened to fall into.
What we're doing: Turn "find two prices that add up to a budget" into a precise, checkable contract.
- 1
- The type hints alone answer two questions the vague prompt left open: prices is a list of numbers, and the answer is a pair of indices, not a pair of prices.
- 2
- The docstring answers the remaining two: which pair, if several match (the first found, by index order), and what "no pair" means (None, not an exception).
Return the (i, j) indices, i < j, of the first pair of prices summing to target; None if no pair exists.Why this works: Every word in the docstring closes a gap the original prompt left open. Writing the contract down, before any implementation exists, means the first time you discover 'what if there are two valid pairs?' is now — a five-second decision — instead of mid-debugging, when it looks like a bug in code that is actually behaving exactly as (accidentally) written.
Remember: Write the restated problem as a function signature and docstring — if you cannot state the exact return type and edge-case behavior, you do not understand the problem yet.

