Index arithmetic and number theory — often O(1) space tricks on matrices.
These problems reward spotting the arithmetic relationship: how indices map when rotating a matrix, the formula for a spiral, or modular tricks for digits. Many matrix problems ask you to do it in place — manipulate indices instead of allocating a copy.
- Rotate / transpose / spiral traverse a matrix.
- In-place marking (set row/col to zero).
- Digit / number manipulation (Plus One, Pow(x, n)).
// 1) transpose, then 2) reverse each row
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
int t = m[i][j]; m[i][j] = m[j][i]; m[j][i] = t;
}
for (int[] row : m) reverse(row);| Problem | Difficulty | Solution |
|---|---|---|
| Plus One | 🟢 | todo |
| Rotate Image | 🟡 | todo |
| Spiral Matrix | 🟡 | todo |
| Set Matrix Zeroes | 🟡 | todo |