Basic Number Theory Problems for Coding Interviews
32 basic Number Theory problems from real coding interviews, each with test cases you can run online. By difficulty they split into 32 basic, 0 intermediate and 0 advanced. The companies that ask them most often are Amazon, Bloomberg, Google, Microsoft.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Greatest Common Divisor of an Array (Basic)
- Ugly Number (Basic)
- Chinese Remainder Solver (Basic)
- Insert GCDs Between Adjacent Nodes (Basic)
- Perfect Number (Basic)
- Prime Arrangements (Basic)
- Delete Nodes at Prime Positions (Basic)
- Divisor Game (Basic)
- Prime Number of Set Bits (Basic)
- Three Divisors (Basic)
- Count Squares of Primes in Range (Basic)
- Totient Values for a List (Basic)
- Highest Power of a Prime Dividing a Product (Basic)
- Count Abundant Numbers up to N (Basic)
- Twin Prime Pairs Below N (Basic)
- Largest Prime Gap Below N (Basic)
- Sum of Primes Below N (Basic)
- Prime Counting Function (Basic)
- Smallest Prime Factor Queries (Basic)
- Largest Prime Factor of N (Basic)
- Mobius Function Value (Basic)
- Liouville Function Value (Basic)
- Radical of an Integer (Basic)
- Squarefree Part of an Integer (Basic)
- Number of Unitary Divisors (Basic)
- Totient Chain Length (Basic)
- Abundant Deficient or Perfect (Basic)
- Largest Square Divisor (Basic)
- Number of Square Divisors (Basic)
- Is Number Powerful (Basic)
- Is Number Smooth (Basic)
- Euclid Division Steps (Basic)
Related
Frequently asked questions
How do I get good at number theory problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run number theory problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.