Topic 20 of 20
Math & Geometry
Matrix manipulation, number tricks and coordinate geometry that show up in interviews.
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
- 1Happy NumberEasy
A digit function that must cycle; fast & slow pointers on numbers.
Cycle Detection on NumbersReported at: GoogleAppleAmazon+3 - 2
- 3
Bijective base-26: the off-by-one that trips everyone.
Base ConversionReported at: MicrosoftGoogleAmazon - 4Rotate ImageMedium
Transpose and reverse, in place; asked very often.
Matrix Rotation / TraversalReported at: MetaMicrosoftAmazon+6 - 5Spiral MatrixMedium
Boundary-shrinking traversal.
Matrix Rotation / TraversalReported at: MicrosoftAmazonApple+4 - 6Set Matrix ZeroesMedium
Use the first row and column as markers for O(1) space.
In-place MarkingReported at: MicrosoftAmazonMeta+2 - 7Game of LifeMedium
Encode old and new state in the same cell.
In-place State EncodingReported at: AmazonGoogleMicrosoft+4 - 8Multiply StringsMedium
Grade-school multiplication with index arithmetic.
Digit & String ArithmeticReported at: MetaMicrosoftGoogle+2 - 9
- 10
Slope hashing with gcd-reduced fractions.
Coordinate Geometry & HashingReported at: AmazonGoogleLinkedIn+1