Math LeetCode Problems: All 485,
With Python Solutions

Every problem in this library that LeetCode tags Math. 413 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.

Easy
121
Medium
244
Hard
120
1 pattern

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.

Eyes only

When the Math problem arrives live.

In the live round, Stealth Interview reads the 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 says. It's a desktop app for macOS and Windows, invisible to screen sharing.

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)

Easy problems
No.Problem
0009Palindrome Number
0013Roman to Integer
0066Plus One
0067Add Binary
0069Sqrt(x)
0070Climbing Stairs
0168Excel Sheet Column Title
0171Excel Sheet Column Number
0202Happy Number
0231Power of Two
0258Add Digits
0263Ugly Number
0268Missing Number
0292Nim Game
0326Power of Three
0342Power of Four
0367Valid Perfect Square
0405Convert a Number to Hexadecimal
0412Fizz Buzz
0415Add Strings
0441Arranging Coins
0492Construct the Rectangle
0504Base 7
0507Perfect Number
0509Fibonacci Number
0598Range Addition II
0628Maximum Product of Three Numbers
0728Self Dividing Numbers
0762Prime Number of Set Bits in Binary Representation
0812Largest Triangle Area
0836Rectangle Overlap
0883Projection Area of 3D Shapes
0892Surface Area of 3D Shapes
0908Smallest Range I
0914X of a Kind in a Deck of Cards
0976Largest Perimeter Triangle
0989Add to Array-Form of Integer
1025Divisor Game
1030Matrix Cells in Distance Order
1037Valid Boomerang
1071Greatest Common Divisor of Strings
1103Distribute Candies to People
1137N-th Tribonacci Number
1154Day of the Year
1175Prime Arrangements
1185Day of the Week
1217Minimum Cost to Move Chips to The Same Position
1232Check If It Is a Straight Line
1252Cells with Odd Values in a Matrix
1266Minimum Time Visiting All Points
1281Subtract the Product and Sum of Digits of an Integer
1290Convert Binary Number in a Linked List to Integer
1295Find Numbers with Even Number of Digits
1304Find N Unique Integers Sum up to Zero
1317Convert Integer to the Sum of Two No-Zero Integers
1323Maximum 69 Number
1342Number of Steps to Reduce a Number to Zero

Medium (103)

Medium problems
No.Problem
0002Add Two Numbers
0007Reverse Integer
0012Integer to Roman
0029Divide Two Integers
0043Multiply Strings
0048Rotate Image
0050Pow(x, n)
0062Unique Paths
0089Gray Code
0096Unique Binary Search Trees
0150Evaluate Reverse Polish Notation
0166Fraction to Recurring Decimal
0172Factorial Trailing Zeroes
0189Rotate Array
0204Count Primes
0223Rectangle Area
0227Basic Calculator II
0241Different Ways to Add Parentheses
0264Ugly Number II
0279Perfect Squares
0313Super Ugly Number
0319Bulb Switcher
0343Integer Break
0357Count Numbers with Unique Digits
0365Water and Jug Problem
0368Largest Divisible Subset
0371Sum of Two Integers
0372Super Pow
0375Guess Number Higher or Lower II
0380Insert Delete GetRandom O(1)
0382Linked List Random Node
0384Shuffle an Array
0390Elimination Game
0396Rotate Function
0398Random Pick Index
0400Nth Digit
0423Reconstruct Original Digits from English
0445Add Two Numbers II
0447Number of Boomerangs
0453Minimum Moves to Equal Array Elements
0462Minimum Moves to Equal Array Elements II
0464Can I Win
0470Implement Rand10() Using Rand7()
0477Total Hamming Distance
0478Generate Random Point in a Circle
0486Predict the Winner
0497Random Point in Non-overlapping Rectangles
0519Random Flip Matrix
0523Continuous Subarray Sum
0528Random Pick with Weight
0537Complex Number Multiplication
0539Minimum Time Difference
0553Optimal Division
0556Next Greater Element III
0592Fraction Addition and Subtraction
0593Valid Square
0633Sum of Square Numbers
0640Solve the Equation
06502 Keys Keyboard
0667Beautiful Arrangement II
0670Maximum Swap
0672Bulb Switcher II
0738Monotone Increasing Digits
0754Reach a Number
0775Global and Local Inversions
0779K-th Symbol in Grammar
0781Rabbits in Forest
0788Rotated Digits
0789Escape The Ghosts
0808Soup Servings
0837New 21 Game
0840Magic Squares In Grid
0858Mirror Reflection
0866Prime Palindrome
0869Reordered Power of 2
0877Stone Game
0910Smallest Range II
0932Beautiful Array
0939Minimum Area Rectangle
0963Minimum Area Rectangle II
0970Powerful Integers
0973K Closest Points to Origin
0991Broken Calculator
1006Clumsy Factorial
1015Smallest Integer Divisible by K
1017Convert to Base -2
1033Moving Stones Until Consecutive
1040Moving Stones Until Consecutive II
1041Robot Bounded In Circle
1073Adding Two Negabinary Numbers
1093Statistics from a Large Sample
1104Path In Zigzag Labelled Binary Tree
1131Maximum of Absolute Value Expression
1140Stone Game II
1201Ugly Number III
1227Airplane Seat Assignment Probability
1237Find Positive Integer Solution for a Given Equation
1238Circular Permutation in Binary Representation
1247Minimum Swaps to Make Strings Equal
1248Count Number of Nice Subarrays
1276Number of Burgers with No Waste of Ingredients
1344Angle Between Hands of a Clock
1352Product of the Last K Numbers

Hard (40)

Hard problems
No.Problem
0060Permutation Sequence
0149Max Points on a Line
0224Basic Calculator
0233Number of Digit One
0273Integer to English Words
0282Expression Add Operators
0335Self Crossing
0381Insert Delete GetRandom O(1) - Duplicates allowed
0391Perfect Rectangle
0458Poor Pigs
0479Largest Palindrome Product
0483Smallest Good Base
0564Find the Closest Palindrome
0587Erect the Fence
0668Kth Smallest Number in Multiplication Table
067924 Game
0710Random Pick with Blacklist
0780Reaching Points
0782Transform to Chessboard
0793Preimage Size of Factorial Zeroes Function
0805Split Array With Same Average
0810Chalkboard XOR Game
0829Consecutive Numbers Sum
0878Nth Magical Number
0887Super Egg Drop
0891Sum of Subsequence Widths
0899Orderly Queue
0902Numbers At Most N Given Digit Set
0906Super Palindromes
0913Cat and Mouse
0920Number of Music Playlists
0927Three Equal Parts
0952Largest Component Size by Common Factor
0964Least Operators to Express Number
0996Number of Squareful Arrays
1012Numbers With Repeated Digits
1250Check If It Is a Good Array
1307Verbal Arithmetic Puzzle
1330Reverse Subarray To Maximize Array Value
1359Count All Valid Pickup and Delivery Options