π’ Math
Math problems reward recognizing the structure: modular arithmetic, GCD, primality, combinatorics, or simple geometry. The right formula usually beats any data-structure cleverness.
This category contains 25 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.
π§ Key Patternsβ
- Modular Arithmetic β
(a + b) % m, modular inverse via Fermat. - GCD / LCM β Euclidean algorithm.
lcm = a / gcd * b. - Prime Sieve β Sieve of Eratosthenes for primes up to in .
- Fast Exponentiation β Power in via repeated squaring.
- Combinatorics β , Pascal's triangle, stars and bars.
- Geometry β Cross product for orientation, distance formula, line intersection.
β οΈ Common Pitfallsβ
- Integer overflow on multiplication β promote to
longearly. - Negative modulo:
(-7) % 3is-1in C#, not2. Addmand re-mod.
π Study Resourcesβ
πΊ Videosβ
π Booksβ
- Concrete Mathematics β Graham, Knuth, Patashnik β The DP-of-math book
- Competitive Programming Handbook β Laaksonen β Ch. 21
π Articles & Referencesβ
π» All Math Problemsβ
Add Digits
LeetCode 258 | Difficulty: Easy
Add Two Integers
LeetCode 2383 | Difficulty: Easy
Angle Between Hands of a Clock
LeetCode 1446 | Difficulty: Medium
Bulb Switcher
LeetCode 319 | Difficulty: Medium
Complement of Base 10 Integer
LeetCode 1054 | Difficulty: Easy
Copy List with Random Pointer
LeetCode 138 | Difficulty: Medium
Count Integers With Even Digit Sum
LeetCode 2298 | Difficulty: Easy
Count Primes
LeetCode 204 | Difficulty: Medium
Fibonacci Number
LeetCode 1013 | Difficulty: Easy
Find N Unique Integers Sum up to Zero
LeetCode 1426 | Difficulty: Easy
Fizz Buzz
LeetCode 412 | Difficulty: Easy
Happy Number
LeetCode 202 | Difficulty: Easy
Integer to Roman
LeetCode 12 | Difficulty: Medium
Largest Rectangle in Histogram
LeetCode 84 | Difficulty: Hard
Minimum Area Rectangle
LeetCode 976 | Difficulty: Medium
Pow(x, n)
LeetCode 50 | Difficulty: Medium
Rectangle Area
LeetCode 223 | Difficulty: Medium
Rectangle Overlap
LeetCode 866 | Difficulty: Easy
Reverse Integer
LeetCode 7 | Difficulty: Medium
Roman to Integer
LeetCode 13 | Difficulty: Easy
Shuffle an Array
LeetCode 384 | Difficulty: Medium
Sqrt(x)
LeetCode 69 | Difficulty: Easy
Sum of Square Numbers
LeetCode 633 | Difficulty: Medium
Three Divisors
LeetCode 2083 | Difficulty: Easy
Ugly Number
LeetCode 263 | Difficulty: Easy