Retrieval: being systematic

Math and Geometry

Retrieval: being systematic

Two problems rebuilt cold, plus the habits that make this unit's problems reliable rather than fiddly.

Key idea

Four habits

Work out the size of the answer before allocating anything. It removes resizing and makes the index arithmetic fixed.

Derive coordinate identities on the smallest example rather than adjusting indexes until the tests pass. A two-by-two grid settles most rotation questions in ten seconds.

Compose hard transformations from easy ones. A rotation is a transpose and a reversal, and neither of those has bounds worth worrying about.

Write the phases down in order when a solution has several, especially when the same storage serves two purposes.

Tip

And the edge cases that recur

A carry running off the front. A grid with one row or one column. A value of zero where the general logic would produce an empty result. A degenerate shape of size zero.

Every problem in this unit has at least one of those, and they are the entire difficulty. None of these problems is hard once the boundary cases are listed.

Which composition rotates counterclockwise?

Transposing then reversing each row rotates a square grid a quarter turn clockwise. Which composition rotates it a quarter turn counterclockwise?

Spiral Matrix, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

Loading the workspace…

Gas Station, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

Loading the workspace…
← Previous