Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Math Patterns
DSA

Math Patterns

Learn common mathematical reasoning patterns used to simplify algorithmic and coding interview problems.

Interview math is a small toolbox applied to disguised problems.

Think number theory when you see:

  • Divisibility, remainders, “mod 10^9+7”
  • Counting pairs/triplets with huge n → formula or precompute
  • Powers that overflow → fast power
  • “How many ways” → combinatorics

Quick Recognition Cheat Sheet

If you see…Think…
Divisor / multiple / coprimeGCD (Euclid)
Primes up to n / prime checksSieve of Eratosthenes
Answer mod 10^9+7Modular arithmetic
Huge exponent / repeated multiplyFast power
”Number of ways to choose”Combinatorics (nCr)
Points, lines, turnsCross product

Pattern Table

PatternTypical QuestionsTrigger
GCD / LCMWater jug, fraction simplifyDivisibility language
Prime sieveCount primes ≤ nMany primality queries
Modular arithmeticBig results mod pOverflow risk
Fast powerpow(x, n), matrix powerExponent too big to loop
CombinatoricsUnique paths, count sequences”How many ways”

Mental Trigger

Overflow or huge loop? → math trick exists. Find it before coding brute force.

Decision Guide

Divisibility question

   GCD via Euclid

Many primality questions

   Sieve once, answer O(1)

Result too big / mod required

   Modular rules + fast power + inverse

"How many ways"

   nCr via Pascal or factorials

My Private Notes

Notes are auto-saved locally to this device.