LeetCodechevron_rightCategorieschevron_rightnumber theory
label

number theory

73 problems
Easy: 11Medium: 30Hard: 32

number theory is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.

Interview Signal

Frequently tests problem modeling, edge handling, and verbal clarity.

Common Pitfall

Template-only answers break under follow-up questioning.

Practice Strategy

Practice in 3-5 problem rounds and always review complexity alternatives.

Recommended Progression

Problem bank

number theory problem bank

Start with a compact scan-friendly list and progressively load more so the topic page stays readable even when the corpus is large.

Progressive topic library

Built for large topic sets: scan the structure first, then go deeper.

hourglass_bottomScroll to continue
search
tuneDifficulty

Showing 24 / 73 problems

+24 per load
#TitleDifficulty
204

Count Primes

Count all prime numbers less than a given integer n using efficient array and math-based enumeration techniques.

Medium
258

Add Digits

Add Digits involves repeatedly summing digits of a number until a single digit is obtained.

Easy
858

Mirror Reflection

Given a square room with mirrors, find which receptor a laser ray will hit first based on two integers, p and q.

Medium
866

Prime Palindrome

The Prime Palindrome problem asks for the smallest prime palindrome greater than or equal to a given integer.

Medium
914

X of a Kind in a Deck of Cards

Solve the problem of determining if a deck can be partitioned into groups with equal occurrences of card values.

Easy
952

Largest Component Size by Common Factor

Find the largest connected component in an array where edges exist between numbers sharing a common factor greater than …

Hard
1201

Ugly Number III

Find the nth positive integer divisible by a, b, or c using binary search over the answer space efficiently and accurate…

Medium
1250

Check If It Is a Good Array

Determine if a given array of positive integers can generate 1 using integer multiples of any subset, leveraging number …

Hard
1447

Simplified Fractions

Generate simplified fractions between 0 and 1 with denominators up to a given integer n.

Medium
1492

The kth Factor of n

Find the kth factor of n by scanning divisors carefully or using factor pairs to skip unnecessary checks.

Medium
1627

Graph Connectivity With Threshold

In 'Graph Connectivity With Threshold,' determine if cities are connected based on common divisors exceeding a threshold…

Hard
1735

Count Ways to Make Array With Product

Determine the number of arrays of size n where the product equals k using prime factorization and combinatorial DP techn…

Hard
1766

Tree of Coprimes

Determine the closest coprime ancestor for each node in a tree using efficient traversal and state tracking of node valu…

Hard
1799

Maximize Score After N Operations

Maximize the score after n operations by selecting pairs from the array and using their GCD with dynamic programming or …

Hard
1808

Maximize Number of Nice Divisors

Solve Maximize Number of Nice Divisors by splitting primeFactors into mostly 3s and using fast modular exponentiation.

Hard
1819

Number of Different Subsequences GCDs

Given an array of positive integers, find the number of different subsequences' GCDs.

Hard
1952

Three Divisors

Determine if a given integer has exactly three positive divisors.

Easy
1979

Find Greatest Common Divisor of Array

Find the greatest common divisor of the smallest and largest numbers in an integer array.

Easy
1994

The Number of Good Subsets

Find the number of good subsets in an integer array, where each subset's product is the product of distinct primes.

Hard
1998

GCD Sort of an Array

The GCD Sort problem challenges you to sort an array using a specific gcd-based swap method.

Hard
2001

Number of Pairs of Interchangeable Rectangles

Count all pairs of rectangles that share the exact width-to-height ratio using efficient array scanning and hash lookup.

Medium
2183

Count Array Pairs Divisible by K

Count Array Pairs Divisible by K requires counting index pairs whose products are divisible by a given number k.

Hard
2197

Replace Non-Coprime Numbers in Array

Replace Non-Coprime Numbers in Array uses stack-based state management to iteratively merge adjacent non-coprime integer…

Hard
2280

Minimum Lines to Represent a Line Chart

Determine the fewest lines needed to accurately connect stock price points in a line chart using array and math reasonin…

Medium

swap_vertScroll inside the bank to auto-load more

Related Patterns

Number Theory LeetCode Problems: 73 Solutions