π’ 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 37 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β
A Number After a Double Reversal
LeetCode 2238 | Difficulty: Easy
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
Check If It Is a Straight Line
LeetCode 1349 | Difficulty: Easy
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 Operations to Obtain Zero
LeetCode 2288 | Difficulty: Easy
Count Primes
LeetCode 204 | Difficulty: Medium
Excel Sheet Column Number
LeetCode 171 | Difficulty: Easy
Excel Sheet Column Title
LeetCode 168 | Difficulty: Easy
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
K-th Symbol in Grammar
LeetCode 795 | Difficulty: Medium
Largest Rectangle in Histogram
LeetCode 84 | Difficulty: Hard
Minimum Area Rectangle
LeetCode 976 | Difficulty: Medium
Minimum Moves to Equal Array Elements
LeetCode 453 | Difficulty: Medium
Minimum Moves to Equal Array Elements II
LeetCode 462 | Difficulty: Medium
Number of Good Pairs
LeetCode 1635 | Difficulty: Easy
Permutation Sequence
LeetCode 60 | Difficulty: Hard
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
Smallest Value of the Rearranged Number
LeetCode 2284 | Difficulty: Medium
Sqrt(x)
LeetCode 69 | Difficulty: Easy
Sum of Absolute Differences in a Sorted Array
LeetCode 1787 | Difficulty: Medium
Sum of Square Numbers
LeetCode 633 | Difficulty: Medium
Three Divisors
LeetCode 2083 | Difficulty: Easy
Ugly Number
LeetCode 263 | Difficulty: Easy