Practice SetLesson 261 min read

Math & Geometry — Practice Problems

November 05, 2026

// How to use this set

Work these in order: easy (Plus One, Happy Number, Roman to Integer) → medium (Rotate Image, Spiral Matrix, Set Matrix Zeroes, Pow(x,n), Multiply Strings, Game of Life, Reverse Integer). The grid problems are about careful in-place index arithmetic; the number problems about digit handling and overflow. Cover the approach, solve it on paper, then type it out and run it. Every solution below was run and tested.

Ten problems that drill the math & geometry pattern from Lesson 26 — the in-place grid manipulations and digit-level number tricks that round out the NeetCode 150. Open a problem, try it yourself first, then read how to reach the solution. Each solution here was actually run and tested.

How to practise. For the grid problems, draw the 3×3 example and write the exact index mapping before you code — most bugs are a swapped i/j or the wrong mutation order. For the number problems, say out loud where overflow would bite in a 32-bit language even though Python is immune. Stuck for ~20 minutes? Read the approach, close the page, and re-solve from memory the next day.

The 10 problems

  1. 1Plus One (LeetCode 66)EasyAdd one to a number stored as a digit array: walk from the right, carry through the 9s, prepend 1 if needed.arrow_forward
  2. 2Happy Number (LeetCode 202)EasyDecide if repeatedly summing squared digits reaches 1: treat the numbers as a list and detect a cycle.arrow_forward
  3. 3Roman to Integer (LeetCode 13)EasyConvert a Roman numeral to an integer: subtract a symbol when a bigger one follows it, otherwise add it.arrow_forward
  4. 4Rotate Image (LeetCode 48)MediumRotate an n×n matrix 90° clockwise in place: transpose across the diagonal, then reverse each row.arrow_forward
  5. 5Spiral Matrix (LeetCode 54)MediumRead a matrix in clockwise spiral order: take the top row, rotate what is left counter-clockwise, repeat.arrow_forward
  6. 6Set Matrix Zeroes (LeetCode 73)MediumZero every row and column that holds a 0, in place, by storing the markers in the first row and column.arrow_forward
  7. 7Pow(x, n) (LeetCode 50)MediumCompute x to the power n in O(log n) by squaring x and multiplying it in for each set bit of n.arrow_forward
  8. 8Multiply Strings (LeetCode 43)MediumMultiply two numeric strings without converting: digit i × digit j lands at positions i+j and i+j+1.arrow_forward
  9. 9Game of Life (LeetCode 289)MediumAdvance Conway's Game of Life one step in place by encoding old and new state in each cell, then taking mod 2.arrow_forward
  10. 10Reverse Integer (LeetCode 7)MediumReverse the digits of a 32-bit integer by popping digits with % 10, and return 0 if the result overflows.arrow_forward