Skip to content

Topic 20 of 20

Math & Geometry

Matrix manipulation, number tricks and coordinate geometry that show up in interviews.

10 problems3 Easy6 Medium1 Hard

The concept

This final topic collects the maths-flavoured questions interviewers still like to ask. Many are really about matrices: rotating an image in place (transpose then reverse each row), walking a matrix in spiral order with shrinking boundaries, or reusing the first row and column as marker storage to zero a matrix in O(1) extra space.

Others are about numbers: multiplying big numbers stored as strings digit by digit, converting between bases (such as spreadsheet column titles), and spotting that repeatedly applying a function must eventually cycle, which lets you reuse fast & slow pointers from the Linked List topic. Geometry questions usually reduce to hashing: represent a slope as a reduced fraction (divide both parts by their gcd) or store points in a map, then count.

None of these need advanced mathematics. What they test is careful implementation (off-by-one boundaries, overflow, precision), so write clean helper functions and test small cases by hand.

Patterns you will learn

Problems, in order

  1. 1

    A digit function that must cycle; fast & slow pointers on numbers.

    Cycle Detection on NumbersReported at: GoogleAppleAmazon+3
  2. 2

    Column addition in base 2.

    Digit & String ArithmeticReported at: MetaAmazonGoogle+3
  3. 3

    Bijective base-26: the off-by-one that trips everyone.

    Base ConversionReported at: MicrosoftGoogleAmazon
  4. 4

    Transpose and reverse, in place; asked very often.

    Matrix Rotation / TraversalReported at: MetaMicrosoftAmazon+6
  5. 5

    Boundary-shrinking traversal.

    Matrix Rotation / TraversalReported at: MicrosoftAmazonApple+4
  6. 6

    Use the first row and column as markers for O(1) space.

    In-place MarkingReported at: MicrosoftAmazonMeta+2
  7. 7

    Encode old and new state in the same cell.

    In-place State EncodingReported at: AmazonGoogleMicrosoft+4
  8. 8

    Grade-school multiplication with index arithmetic.

    Digit & String ArithmeticReported at: MetaMicrosoftGoogle+2
  9. 9

    Counting squares with a point-frequency map.

  10. 10

    Slope hashing with gcd-reduced fractions.

    Coordinate Geometry & HashingReported at: AmazonGoogleLinkedIn+1