Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

17 · Math & Geometry

Index arithmetic and number theory — often O(1) space tricks on matrices.

🧠 Intuition

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.

🕵️ When to reach for it

  • Rotate / transpose / spiral traverse a matrix.
  • In-place marking (set row/col to zero).
  • Digit / number manipulation (Plus One, Pow(x, n)).

🧩 Trick (rotate matrix 90° in place)

// 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);

📝 Problems

Problem Difficulty Solution
Plus One 🟢 todo
Rotate Image 🟡 todo
Spiral Matrix 🟡 todo
Set Matrix Zeroes 🟡 todo