Math & Number Theory Master Recap: Interview Cheatsheet
Complete reference for math and number theory DSA patterns: algorithm selection guide, complexity table, and top 25 interview problems.
webcoderspeed.com
20 articles
Complete reference for math and number theory DSA patterns: algorithm selection guide, complexity table, and top 25 interview problems.
Apply the inclusion-exclusion principle to count elements satisfying union of conditions. Solves divisibility, coverage, and derangement problems.
Master randomized DSA algorithms: reservoir sampling for streams, quickselect for O(n) kth element, and random shuffling.
Master combinatorial game theory: Nim XOR strategy, Grundy (nimber) values, and Sprague-Grundy theorem for composite games.
Tackle geometry problems in coding interviews: cross product, point-in-polygon, line intersection, and Graham scan convex hull.
Apply probability theory and expected value DP to competitive programming: dice problems, random walks, and geometric distribution.
Prevent integer overflow in competitive programming: safe multiplication, __int128, binary search on answers, and floating-point gotchas.
Build range query structures in O(sqrt n) per query with block decomposition. Simpler alternative to segment trees.
Solve systems of modular congruences with the Chinese Remainder Theorem. Fundamental for cryptography and competitive math.
Explore classic number sequences: Fibonacci, Lucas, Pell, tribonacci, with DP and matrix approaches.
Master bitwise operations for DSA: XOR tricks, Brian Kernighan bit counting, subset enumeration, and bitmask DP.
Solve linear recurrences like Fibonacci in O(log n) using matrix exponentiation. Essential for DP optimization on large n.
Explore digit manipulation, perfect/abundant numbers, Armstrong numbers, and common math interview patterns.
Compute combinations nCr efficiently with precomputed factorials, Pascal's triangle for small n, and Catalan numbers for tree/parenthesis counting.
Compute Euler's totient phi(n) for cryptography and modular inverse applications. Sieve variant for all values up to n.
Factor integers efficiently with trial division O(sqrt n), SPF sieve O(log n), and understand when each approach is optimal.
Master modular arithmetic for competitive programming: binary exponentiation O(log n), modular inverse, and Chinese Remainder Theorem.
Master GCD/LCM with Euclidean algorithm O(log n) and the Extended Euclidean for modular inverse computation.
Generate all primes up to n in O(n log log n) with the Sieve of Eratosthenes. Includes segmented sieve and prime factorization variants.
Master mathematical algorithms for DSA: primes, GCD, modular arithmetic, combinatorics, and fast exponentiation with 5-language implementations.