Math LeetCode Problems: All 485, With Python Solutions
Every problem in this library that LeetCode tags Math — 485 in total, 413 of them with a complete Python solution, a worked example and the time and space complexity of the approach.
- 485 problems
- 121 Easy
- 244 Medium
- 120 Hard
How Math problems are solved
A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Math problems — each one explains the approach, gives a Python template and states its complexity.
- Math and Number Theory — Find the closed form, the invariant, or the modular identity — and skip the loop entirely.
Math problems by difficulty
Showing the first 200 of 485 problems. Problems with a complete Python solution are listed first, then by ascending problem number.
Easy (57)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 9 | Palindrome Number | Easy | Math |
| 13 | Roman to Integer | Easy | Hash Table, Math, String |
| 66 | Plus One | Easy | Array, Math |
| 67 | Add Binary | Easy | Bit Manipulation, Math, String +1 |
| 69 | Sqrt(x) | Easy | Math, Binary Search |
| 70 | Climbing Stairs | Easy | Memoization, Math, Dynamic Programming |
| 168 | Excel Sheet Column Title | Easy | Math, String |
| 171 | Excel Sheet Column Number | Easy | Math, String |
| 202 | Happy Number | Easy | Hash Table, Math, Two Pointers |
| 231 | Power of Two | Easy | Bit Manipulation, Recursion, Math |
| 258 | Add Digits | Easy | Math, Number Theory, Simulation |
| 263 | Ugly Number | Easy | Math |
| 268 | Missing Number | Easy | Bit Manipulation, Array, Hash Table +3 |
| 292 | Nim Game | Easy | Brainteaser, Math, Game Theory |
| 326 | Power of Three | Easy | Recursion, Math |
| 342 | Power of Four | Easy | Bit Manipulation, Recursion, Math |
| 367 | Valid Perfect Square | Easy | Math, Binary Search |
| 405 | Convert a Number to Hexadecimal | Easy | Bit Manipulation, Math, String |
| 412 | Fizz Buzz | Easy | Math, String, Simulation |
| 415 | Add Strings | Easy | Math, String, Simulation |
| 441 | Arranging Coins | Easy | Math, Binary Search |
| 492 | Construct the Rectangle | Easy | Math |
| 504 | Base 7 | Easy | Math, String |
| 507 | Perfect Number | Easy | Math |
| 509 | Fibonacci Number | Easy | Recursion, Memoization, Math +1 |
| 598 | Range Addition II | Easy | Array, Math |
| 628 | Maximum Product of Three Numbers | Easy | Array, Math, Sorting |
| 728 | Self Dividing Numbers | Easy | Math |
| 762 | Prime Number of Set Bits in Binary Representation | Easy | Bit Manipulation, Math |
| 812 | Largest Triangle Area | Easy | Geometry, Array, Math |
| 836 | Rectangle Overlap | Easy | Geometry, Math |
| 883 | Projection Area of 3D Shapes | Easy | Geometry, Array, Math +1 |
| 892 | Surface Area of 3D Shapes | Easy | Geometry, Array, Math +1 |
| 908 | Smallest Range I | Easy | Array, Math |
| 914 | X of a Kind in a Deck of Cards | Easy | Array, Hash Table, Math +2 |
| 976 | Largest Perimeter Triangle | Easy | Greedy, Array, Math +1 |
| 989 | Add to Array-Form of Integer | Easy | Array, Math |
| 1025 | Divisor Game | Easy | Brainteaser, Math, Dynamic Programming +1 |
| 1030 | Matrix Cells in Distance Order | Easy | Geometry, Array, Math +2 |
| 1037 | Valid Boomerang | Easy | Geometry, Array, Math |
| 1071 | Greatest Common Divisor of Strings | Easy | Math, String |
| 1103 | Distribute Candies to People | Easy | Math, Simulation |
| 1137 | N-th Tribonacci Number | Easy | Memoization, Math, Dynamic Programming |
| 1154 | Day of the Year | Easy | Math, String |
| 1175 | Prime Arrangements | Easy | Math |
| 1185 | Day of the Week | Easy | Math |
| 1217 | Minimum Cost to Move Chips to The Same Position | Easy | Greedy, Array, Math |
| 1232 | Check If It Is a Straight Line | Easy | Geometry, Array, Math |
| 1252 | Cells with Odd Values in a Matrix | Easy | Array, Math, Simulation |
| 1266 | Minimum Time Visiting All Points | Easy | Geometry, Array, Math |
| 1281 | Subtract the Product and Sum of Digits of an Integer | Easy | Math |
| 1290 | Convert Binary Number in a Linked List to Integer | Easy | Linked List, Math |
| 1295 | Find Numbers with Even Number of Digits | Easy | Array, Math |
| 1304 | Find N Unique Integers Sum up to Zero | Easy | Array, Math |
| 1317 | Convert Integer to the Sum of Two No-Zero Integers | Easy | Math |
| 1323 | Maximum 69 Number | Easy | Greedy, Math |
| 1342 | Number of Steps to Reduce a Number to Zero | Easy | Bit Manipulation, Math |
Medium (103)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 2 | Add Two Numbers | Medium | Recursion, Linked List, Math |
| 7 | Reverse Integer | Medium | Math |
| 12 | Integer to Roman | Medium | Hash Table, Math, String |
| 29 | Divide Two Integers | Medium | Bit Manipulation, Math |
| 43 | Multiply Strings | Medium | Math, String, Simulation |
| 48 | Rotate Image | Medium | Array, Math, Matrix |
| 50 | Pow(x, n) | Medium | Recursion, Math |
| 62 | Unique Paths | Medium | Math, Dynamic Programming, Combinatorics |
| 89 | Gray Code | Medium | Bit Manipulation, Math, Backtracking |
| 96 | Unique Binary Search Trees | Medium | Tree, Binary Search Tree, Math +2 |
| 150 | Evaluate Reverse Polish Notation | Medium | Stack, Array, Math |
| 166 | Fraction to Recurring Decimal | Medium | Hash Table, Math, String |
| 172 | Factorial Trailing Zeroes | Medium | Math |
| 189 | Rotate Array | Medium | Array, Math, Two Pointers |
| 204 | Count Primes | Medium | Array, Math, Enumeration +1 |
| 223 | Rectangle Area | Medium | Geometry, Math |
| 227 | Basic Calculator II | Medium | Stack, Math, String |
| 241 | Different Ways to Add Parentheses | Medium | Recursion, Memoization, Math +2 |
| 264 | Ugly Number II | Medium | Hash Table, Math, Dynamic Programming +1 |
| 279 | Perfect Squares | Medium | Breadth-First Search, Math, Dynamic Programming |
| 313 | Super Ugly Number | Medium | Array, Math, Dynamic Programming |
| 319 | Bulb Switcher | Medium | Brainteaser, Math |
| 343 | Integer Break | Medium | Math, Dynamic Programming |
| 357 | Count Numbers with Unique Digits | Medium | Math, Dynamic Programming, Backtracking |
| 365 | Water and Jug Problem | Medium | Depth-First Search, Breadth-First Search, Math |
| 368 | Largest Divisible Subset | Medium | Array, Math, Dynamic Programming +1 |
| 371 | Sum of Two Integers | Medium | Bit Manipulation, Math |
| 372 | Super Pow | Medium | Math, Divide and Conquer |
| 375 | Guess Number Higher or Lower II | Medium | Math, Dynamic Programming, Game Theory |
| 380 | Insert Delete GetRandom O(1) | Medium | Design, Array, Hash Table +2 |
| 382 | Linked List Random Node | Medium | Reservoir Sampling, Linked List, Math +1 |
| 384 | Shuffle an Array | Medium | Design, Array, Math +1 |
| 390 | Elimination Game | Medium | Recursion, Math |
| 396 | Rotate Function | Medium | Array, Math, Dynamic Programming |
| 398 | Random Pick Index | Medium | Reservoir Sampling, Hash Table, Math +1 |
| 400 | Nth Digit | Medium | Math, Binary Search |
| 423 | Reconstruct Original Digits from English | Medium | Hash Table, Math, String |
| 445 | Add Two Numbers II | Medium | Stack, Linked List, Math |
| 447 | Number of Boomerangs | Medium | Array, Hash Table, Math |
| 453 | Minimum Moves to Equal Array Elements | Medium | Array, Math |
| 462 | Minimum Moves to Equal Array Elements II | Medium | Array, Math, Sorting |
| 464 | Can I Win | Medium | Bit Manipulation, Memoization, Math +3 |
| 470 | Implement Rand10() Using Rand7() | Medium | Math, Rejection Sampling, Probability and Statistics +1 |
| 477 | Total Hamming Distance | Medium | Bit Manipulation, Array, Math |
| 478 | Generate Random Point in a Circle | Medium | Geometry, Math, Rejection Sampling +1 |
| 486 | Predict the Winner | Medium | Recursion, Array, Math +2 |
| 497 | Random Point in Non-overlapping Rectangles | Medium | Reservoir Sampling, Array, Math +4 |
| 519 | Random Flip Matrix | Medium | Reservoir Sampling, Hash Table, Math +1 |
| 523 | Continuous Subarray Sum | Medium | Array, Hash Table, Math +1 |
| 528 | Random Pick with Weight | Medium | Array, Math, Binary Search +2 |
| 537 | Complex Number Multiplication | Medium | Math, String, Simulation |
| 539 | Minimum Time Difference | Medium | Array, Math, String +1 |
| 553 | Optimal Division | Medium | Array, Math, Dynamic Programming |
| 556 | Next Greater Element III | Medium | Math, Two Pointers, String |
| 592 | Fraction Addition and Subtraction | Medium | Math, String, Simulation |
| 593 | Valid Square | Medium | Geometry, Math |
| 633 | Sum of Square Numbers | Medium | Math, Two Pointers, Binary Search |
| 640 | Solve the Equation | Medium | Math, String, Simulation |
| 650 | 2 Keys Keyboard | Medium | Math, Dynamic Programming |
| 667 | Beautiful Arrangement II | Medium | Array, Math |
| 670 | Maximum Swap | Medium | Greedy, Math |
| 672 | Bulb Switcher II | Medium | Bit Manipulation, Depth-First Search, Breadth-First Search +1 |
| 738 | Monotone Increasing Digits | Medium | Greedy, Math |
| 754 | Reach a Number | Medium | Math, Binary Search |
| 775 | Global and Local Inversions | Medium | Array, Math |
| 779 | K-th Symbol in Grammar | Medium | Bit Manipulation, Recursion, Math |
| 781 | Rabbits in Forest | Medium | Greedy, Array, Hash Table +1 |
| 788 | Rotated Digits | Medium | Math, Dynamic Programming |
| 789 | Escape The Ghosts | Medium | Array, Math |
| 808 | Soup Servings | Medium | Math, Dynamic Programming, Probability and Statistics |
| 837 | New 21 Game | Medium | Math, Dynamic Programming, Sliding Window +1 |
| 840 | Magic Squares In Grid | Medium | Array, Hash Table, Math +1 |
| 858 | Mirror Reflection | Medium | Geometry, Math, Number Theory |
| 866 | Prime Palindrome | Medium | Math, Number Theory |
| 869 | Reordered Power of 2 | Medium | Hash Table, Math, Counting +2 |
| 877 | Stone Game | Medium | Array, Math, Dynamic Programming +1 |
| 910 | Smallest Range II | Medium | Greedy, Array, Math +1 |
| 932 | Beautiful Array | Medium | Array, Math, Divide and Conquer |
| 939 | Minimum Area Rectangle | Medium | Geometry, Array, Hash Table +2 |
| 963 | Minimum Area Rectangle II | Medium | Geometry, Array, Hash Table +1 |
| 970 | Powerful Integers | Medium | Hash Table, Math, Enumeration |
| 973 | K Closest Points to Origin | Medium | Geometry, Array, Math +4 |
| 991 | Broken Calculator | Medium | Greedy, Math |
| 1006 | Clumsy Factorial | Medium | Stack, Math, Simulation |
| 1015 | Smallest Integer Divisible by K | Medium | Hash Table, Math |
| 1017 | Convert to Base -2 | Medium | Math |
| 1033 | Moving Stones Until Consecutive | Medium | Brainteaser, Math |
| 1040 | Moving Stones Until Consecutive II | Medium | Array, Math, Sorting +1 |
| 1041 | Robot Bounded In Circle | Medium | Math, String, Simulation |
| 1073 | Adding Two Negabinary Numbers | Medium | Array, Math |
| 1093 | Statistics from a Large Sample | Medium | Array, Math, Probability and Statistics |
| 1104 | Path In Zigzag Labelled Binary Tree | Medium | Tree, Math, Binary Tree |
| 1131 | Maximum of Absolute Value Expression | Medium | Array, Math |
| 1140 | Stone Game II | Medium | Array, Math, Dynamic Programming +2 |
| 1201 | Ugly Number III | Medium | Math, Binary Search, Combinatorics +1 |
| 1227 | Airplane Seat Assignment Probability | Medium | Brainteaser, Math, Dynamic Programming +1 |
| 1237 | Find Positive Integer Solution for a Given Equation | Medium | Math, Two Pointers, Binary Search +1 |
| 1238 | Circular Permutation in Binary Representation | Medium | Bit Manipulation, Math, Backtracking |
| 1247 | Minimum Swaps to Make Strings Equal | Medium | Greedy, Math, String |
| 1248 | Count Number of Nice Subarrays | Medium | Array, Hash Table, Math +2 |
| 1276 | Number of Burgers with No Waste of Ingredients | Medium | Math |
| 1344 | Angle Between Hands of a Clock | Medium | Math |
| 1352 | Product of the Last K Numbers | Medium | Design, Array, Math +2 |
Hard (40)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 60 | Permutation Sequence | Hard | Recursion, Math |
| 149 | Max Points on a Line | Hard | Geometry, Array, Hash Table +1 |
| 224 | Basic Calculator | Hard | Stack, Recursion, Math +1 |
| 233 | Number of Digit One | Hard | Recursion, Math, Dynamic Programming |
| 273 | Integer to English Words | Hard | Recursion, Math, String |
| 282 | Expression Add Operators | Hard | Math, String, Backtracking |
| 335 | Self Crossing | Hard | Geometry, Array, Math |
| 381 | Insert Delete GetRandom O(1) - Duplicates allowed | Hard | Design, Array, Hash Table +2 |
| 391 | Perfect Rectangle | Hard | Geometry, Array, Hash Table +2 |
| 458 | Poor Pigs | Hard | Math, Dynamic Programming, Combinatorics |
| 479 | Largest Palindrome Product | Hard | Math, Enumeration |
| 483 | Smallest Good Base | Hard | Math, Binary Search |
| 564 | Find the Closest Palindrome | Hard | Math, String |
| 587 | Erect the Fence | Hard | Geometry, Array, Math |
| 668 | Kth Smallest Number in Multiplication Table | Hard | Math, Binary Search |
| 679 | 24 Game | Hard | Array, Math, Backtracking |
| 710 | Random Pick with Blacklist | Hard | Array, Hash Table, Math +3 |
| 780 | Reaching Points | Hard | Math |
| 782 | Transform to Chessboard | Hard | Bit Manipulation, Array, Math +1 |
| 793 | Preimage Size of Factorial Zeroes Function | Hard | Math, Binary Search |
| 805 | Split Array With Same Average | Hard | Bit Manipulation, Array, Math +2 |
| 810 | Chalkboard XOR Game | Hard | Bit Manipulation, Brainteaser, Array +2 |
| 829 | Consecutive Numbers Sum | Hard | Math, Enumeration |
| 878 | Nth Magical Number | Hard | Math, Binary Search |
| 887 | Super Egg Drop | Hard | Math, Binary Search, Dynamic Programming |
| 891 | Sum of Subsequence Widths | Hard | Array, Math, Sorting |
| 899 | Orderly Queue | Hard | Math, String, Sorting |
| 902 | Numbers At Most N Given Digit Set | Hard | Array, Math, String +2 |
| 906 | Super Palindromes | Hard | Math, String, Enumeration |
| 913 | Cat and Mouse | Hard | Graph, Topological Sort, Memoization +3 |
| 920 | Number of Music Playlists | Hard | Math, Dynamic Programming, Combinatorics |
| 927 | Three Equal Parts | Hard | Array, Math |
| 952 | Largest Component Size by Common Factor | Hard | Union Find, Array, Hash Table +2 |
| 964 | Least Operators to Express Number | Hard | Memoization, Math, Dynamic Programming |
| 996 | Number of Squareful Arrays | Hard | Bit Manipulation, Array, Hash Table +4 |
| 1012 | Numbers With Repeated Digits | Hard | Math, Dynamic Programming |
| 1250 | Check If It Is a Good Array | Hard | Array, Math, Number Theory |
| 1307 | Verbal Arithmetic Puzzle | Hard | Array, Math, String +1 |
| 1330 | Reverse Subarray To Maximize Array Value | Hard | Greedy, Array, Math |
| 1359 | Count All Valid Pickup and Delivery Options | Hard | Math, Dynamic Programming, Combinatorics |
Keep exploring
- Array1,569
- String672
- Hash Table588
- Dynamic Programming481
- Sorting392
- Greedy346
- Depth-First Search289
- Binary Search253
- Database249
- Tree225
- Breadth-First Search223
- Matrix216
- Two Pointers201
- Bit Manipulation194
- Binary Tree174
- Heap (Priority Queue)163
- Prefix Sum157
- Stack157
- Simulation144
- Graph138
- Counting126
- Design122
- Sliding Window116
- Backtracking105
When the Math problem arrives live
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.