Technique
Simulation & Matrix Traversal
Carry out exactly what the statement describes with careful index bookkeeping (layers, directions, in-place swaps).
0%
mastery
0/22 solved
0/22 solved
Recognise it
The signal
spiral/rotate/transpose a matrix
1Brute force
The brute force is the solution; the skill is clean boundaries and in-place tricks.
2The observation
Extra copies of the grid: encode old/new state in the same cell, or rotate by transpose + reverse.
3Why it works
Problem-specific: the processed boundary (layer, direction) shrinks each step.
Reach for it when
- +follow rules step by step with small limits
- +game-of-life style updates in place
Not when
- ×number of steps is huge (find a cycle with functional-graph, or a formula with math)
Practice
0/22 solved
- Plus OneAdobe, GoogleEasy
- Longest Common PrefixAdobe, AmazonEasy
- Reverse StringApple, AdobeEasy
- Roman to IntegerAmazon, AdobeEasy
- Add BinaryMeta, AmazonEasy
- Pascal's TriangleAmazon, Morgan StanleyEasy
- Weird AlgorithmCSESEasy
- Bit++Codeforces800
- Following DirectionsCodeforces800
- Run-Length Encode a StringGoldman Sachs, SalesforceOAEasy
- Spiral MatrixMicrosoft, AmazonMedium
- Rotate ImageAmazon, MicrosoftMedium
Pitfalls
Misconceptions
- !off-by-one at layer boundaries in spiral order
Looks like it, isn't
- Bitwise AND of Numbers Range needs Bit Tricks & Bitmasking
Why
Looping is O(range); the answer is the common binary prefix.