# Number Theory DSA Problems

> 73 Number Theory coding problems for placements and interviews, sorted easiest first, with hints and company tags. Free practice on InternHack.

Canonical: https://www.internhack.in/learn/dsa/number-theory
Last updated: 2026-11-28

73 number theory problems for coding interviews and campus placements, with hints and company tags. Below are all 73: 10 easy, 32 medium and 31 hard. Practise them free on InternHack and track what you have solved.

## Number Theory problems, easiest first

1. [Add Digits](https://www.internhack.in/learn/dsa/problem/add-digits) (Easy)
2. [Check If Digits Are Equal in String After Operations I](https://www.internhack.in/learn/dsa/problem/check-if-digits-are-equal-in-string-after-operations-i) (Easy)
3. [Find Greatest Common Divisor of Array](https://www.internhack.in/learn/dsa/problem/find-greatest-common-divisor-of-array) (Easy)
4. [GCD of Odd and Even Sums](https://www.internhack.in/learn/dsa/problem/gcd-of-odd-and-even-sums) (Easy)
5. [Maximum Subarray With Equal Products](https://www.internhack.in/learn/dsa/problem/maximum-subarray-with-equal-products) (Easy)
6. [Number of Common Factors](https://www.internhack.in/learn/dsa/problem/number-of-common-factors) (Easy)
7. [Prime In Diagonal](https://www.internhack.in/learn/dsa/problem/prime-in-diagonal) (Easy)
8. [Smallest Even Multiple](https://www.internhack.in/learn/dsa/problem/smallest-even-multiple) (Easy)
9. [Three Divisors](https://www.internhack.in/learn/dsa/problem/three-divisors) (Easy)
10. [X of a Kind in a Deck of Cards](https://www.internhack.in/learn/dsa/problem/x-of-a-kind-in-a-deck-of-cards) (Easy)
11. [Balanced K-Factor Decomposition](https://www.internhack.in/learn/dsa/problem/balanced-k-factor-decomposition) (Medium)
12. [Closest Prime Numbers in Range](https://www.internhack.in/learn/dsa/problem/closest-prime-numbers-in-range) (Medium)
13. [Count Beautiful Substrings I](https://www.internhack.in/learn/dsa/problem/count-beautiful-substrings-i) (Medium)
14. [Count Prime-Gap Balanced Subarrays](https://www.internhack.in/learn/dsa/problem/count-prime-gap-balanced-subarrays) (Medium)
15. [Count Primes](https://www.internhack.in/learn/dsa/problem/count-primes) (Medium)
16. [Digit Operations to Make Two Integers Equal](https://www.internhack.in/learn/dsa/problem/digit-operations-to-make-two-integers-equal) (Medium)
17. [Distinct Prime Factors of Product of Array](https://www.internhack.in/learn/dsa/problem/distinct-prime-factors-of-product-of-array) (Medium)
18. [Find the Maximum Factor Score of Array](https://www.internhack.in/learn/dsa/problem/find-the-maximum-factor-score-of-array) (Medium)
19. [Find Triangular Sum of an Array](https://www.internhack.in/learn/dsa/problem/find-triangular-sum-of-an-array) (Medium)
20. [Insert Greatest Common Divisors in Linked List](https://www.internhack.in/learn/dsa/problem/insert-greatest-common-divisors-in-linked-list) (Medium)
21. [Largest Prime from Consecutive Prime Sum](https://www.internhack.in/learn/dsa/problem/largest-prime-from-consecutive-prime-sum) (Medium)
22. [Make K-Subarray Sums Equal](https://www.internhack.in/learn/dsa/problem/make-k-subarray-sums-equal) (Medium)
23. [Maximum Prime Difference](https://www.internhack.in/learn/dsa/problem/maximum-prime-difference) (Medium)
24. [Minimize Length of Array Using Operations](https://www.internhack.in/learn/dsa/problem/minimize-length-of-array-using-operations) (Medium)
25. [Minimize the Maximum of Two Arrays](https://www.internhack.in/learn/dsa/problem/minimize-the-maximum-of-two-arrays) (Medium)
26. [Minimum Division Operations to Make Array Non Decreasing](https://www.internhack.in/learn/dsa/problem/minimum-division-operations-to-make-array-non-decreasing) (Medium)
27. [Minimum Jumps to Reach End via Prime Teleportation](https://www.internhack.in/learn/dsa/problem/minimum-jumps-to-reach-end-via-prime-teleportation) (Medium)
28. [Minimum Lines to Represent a Line Chart](https://www.internhack.in/learn/dsa/problem/minimum-lines-to-represent-a-line-chart) (Medium)
29. [Minimum Number of Operations to Make All Array Elements Equal to 1](https://www.internhack.in/learn/dsa/problem/minimum-number-of-operations-to-make-all-array-elements-equal-to-1) (Medium)
30. [Minimum Number of Primes to Sum to Target](https://www.internhack.in/learn/dsa/problem/minimum-number-of-primes-to-sum-to-target) (Medium)
31. [Mirror Reflection](https://www.internhack.in/learn/dsa/problem/mirror-reflection) (Medium)
32. [Most Expensive Item That Can Not Be Bought](https://www.internhack.in/learn/dsa/problem/most-expensive-item-that-can-not-be-bought) (Medium)
33. [Most Frequent Prime](https://www.internhack.in/learn/dsa/problem/most-frequent-prime) (Medium)
34. [Number of Pairs of Interchangeable Rectangles](https://www.internhack.in/learn/dsa/problem/number-of-pairs-of-interchangeable-rectangles) (Medium)
35. [Number of Self-Divisible Permutations](https://www.internhack.in/learn/dsa/problem/number-of-self-divisible-permutations) (Medium)
36. [Number of Subarrays With LCM Equal to K](https://www.internhack.in/learn/dsa/problem/number-of-subarrays-with-lcm-equal-to-k) (Medium)
37. [Prime Palindrome](https://www.internhack.in/learn/dsa/problem/prime-palindrome) (Medium)
38. [Prime Subtraction Operation](https://www.internhack.in/learn/dsa/problem/prime-subtraction-operation) (Medium)
39. [Simplified Fractions](https://www.internhack.in/learn/dsa/problem/simplified-fractions) (Medium)
40. [Sum of Largest Prime Substrings](https://www.internhack.in/learn/dsa/problem/sum-of-largest-prime-substrings) (Medium)
41. [The kth Factor of n](https://www.internhack.in/learn/dsa/problem/the-kth-factor-of-n) (Medium)
42. [Ugly Number III](https://www.internhack.in/learn/dsa/problem/ugly-number-iii) (Medium)
43. [Abbreviating the Product of a Range](https://www.internhack.in/learn/dsa/problem/abbreviating-the-product-of-a-range) (Hard)
44. [Apply Operations to Maximize Score](https://www.internhack.in/learn/dsa/problem/apply-operations-to-maximize-score) (Hard)
45. [Check If Digits Are Equal in String After Operations II](https://www.internhack.in/learn/dsa/problem/check-if-digits-are-equal-in-string-after-operations-ii) (Hard)
46. [Check If It Is a Good Array](https://www.internhack.in/learn/dsa/problem/check-if-it-is-a-good-array) (Hard)
47. [Check if Point Is Reachable](https://www.internhack.in/learn/dsa/problem/check-if-point-is-reachable) (Hard)
48. [Count Array Pairs Divisible by K](https://www.internhack.in/learn/dsa/problem/count-array-pairs-divisible-by-k) (Hard)
49. [Count Beautiful Substrings II](https://www.internhack.in/learn/dsa/problem/count-beautiful-substrings-ii) (Hard)
50. [Count the Number of Ideal Arrays](https://www.internhack.in/learn/dsa/problem/count-the-number-of-ideal-arrays) (Hard)
51. [Count Valid Paths in a Tree](https://www.internhack.in/learn/dsa/problem/count-valid-paths-in-a-tree) (Hard)
52. [Count Ways to Make Array With Product](https://www.internhack.in/learn/dsa/problem/count-ways-to-make-array-with-product) (Hard)
53. [Find the Largest Palindrome Divisible by K](https://www.internhack.in/learn/dsa/problem/find-the-largest-palindrome-divisible-by-k) (Hard)
54. [Find the Number of Subsequences With Equal GCD](https://www.internhack.in/learn/dsa/problem/find-the-number-of-subsequences-with-equal-gcd) (Hard)
55. [GCD Sort of an Array](https://www.internhack.in/learn/dsa/problem/gcd-sort-of-an-array) (Hard)
56. [Graph Connectivity With Threshold](https://www.internhack.in/learn/dsa/problem/graph-connectivity-with-threshold) (Hard)
57. [Largest Component Size by Common Factor](https://www.internhack.in/learn/dsa/problem/largest-component-size-by-common-factor) (Hard)
58. [Maximize Number of Nice Divisors](https://www.internhack.in/learn/dsa/problem/maximize-number-of-nice-divisors) (Hard)
59. [Maximize Score After N Operations](https://www.internhack.in/learn/dsa/problem/maximize-score-after-n-operations) (Hard)
60. [Maximize Subarray GCD Score](https://www.internhack.in/learn/dsa/problem/maximize-subarray-gcd-score) (Hard)
61. [Maximum Element-Sum of a Complete Subset of Indices](https://www.internhack.in/learn/dsa/problem/maximum-element-sum-of-a-complete-subset-of-indices) (Hard)
62. [Maximum GCD-Sum of a Subarray](https://www.internhack.in/learn/dsa/problem/maximum-gcd-sum-of-a-subarray) (Hard)
63. [Minimum Deletions to Make Array Divisible](https://www.internhack.in/learn/dsa/problem/minimum-deletions-to-make-array-divisible) (Hard)
64. [Minimum Stability Factor of Array](https://www.internhack.in/learn/dsa/problem/minimum-stability-factor-of-array) (Hard)
65. [Number of Different Subsequences GCDs](https://www.internhack.in/learn/dsa/problem/number-of-different-subsequences-gcds) (Hard)
66. [Replace Non-Coprime Numbers in Array](https://www.internhack.in/learn/dsa/problem/replace-non-coprime-numbers-in-array) (Hard)
67. [Smallest Divisible Digit Product II](https://www.internhack.in/learn/dsa/problem/smallest-divisible-digit-product-ii) (Hard)
68. [Sorted GCD Pair Queries](https://www.internhack.in/learn/dsa/problem/sorted-gcd-pair-queries) (Hard)
69. [Split the Array to Make Coprime Products](https://www.internhack.in/learn/dsa/problem/split-the-array-to-make-coprime-products) (Hard)
70. [Sum of Beautiful Subsequences](https://www.internhack.in/learn/dsa/problem/sum-of-beautiful-subsequences) (Hard)
71. [Sum of Perfect Square Ancestors](https://www.internhack.in/learn/dsa/problem/sum-of-perfect-square-ancestors) (Hard)
72. [The Number of Good Subsets](https://www.internhack.in/learn/dsa/problem/the-number-of-good-subsets) (Hard)
73. [Tree of Coprimes](https://www.internhack.in/learn/dsa/problem/tree-of-coprimes) (Hard)

## Companies that ask number theory problems

- [Google](https://www.internhack.in/learn/dsa/companies/google): 40 of these problems
- [Amazon](https://www.internhack.in/learn/dsa/companies/amazon): 31 of these problems
- [Microsoft](https://www.internhack.in/learn/dsa/companies/microsoft): 19 of these problems
- [Bloomberg](https://www.internhack.in/learn/dsa/companies/bloomberg): 12 of these problems
- [Meta](https://www.internhack.in/learn/dsa/companies/meta): 12 of these problems
- [Infosys](https://www.internhack.in/learn/dsa/companies/infosys): 5 of these problems
- [Uber](https://www.internhack.in/learn/dsa/companies/uber): 5 of these problems
- [Goldman Sachs](https://www.internhack.in/learn/dsa/companies/goldman-sachs): 3 of these problems
- [Oracle](https://www.internhack.in/learn/dsa/companies/oracle): 3 of these problems
- [Adobe](https://www.internhack.in/learn/dsa/companies/adobe): 2 of these problems
- [Zoho](https://www.internhack.in/learn/dsa/companies/zoho): 2 of these problems
- [Nokia](https://www.internhack.in/learn/dsa/companies/nokia): 2 of these problems

## Before your interview

Most resumes are filtered by software before a recruiter reads them. [Check your resume ATS score free](https://www.internhack.in/ats-score/try), no signup needed.

## Other DSA topics

- [Array](https://www.internhack.in/learn/dsa/array) (1869)
- [String](https://www.internhack.in/learn/dsa/string) (775)
- [Hash Table](https://www.internhack.in/learn/dsa/hash-table) (708)
- [Math](https://www.internhack.in/learn/dsa/math) (564)
- [Dynamic Programming](https://www.internhack.in/learn/dsa/dynamic-programming) (557)
- [Sorting](https://www.internhack.in/learn/dsa/sorting) (464)
- [Greedy](https://www.internhack.in/learn/dsa/greedy) (407)
- [Depth-First Search](https://www.internhack.in/learn/dsa/depth-first-search) (314)
- [Binary Search](https://www.internhack.in/learn/dsa/binary-search) (298)
- [Matrix](https://www.internhack.in/learn/dsa/matrix) (246)
- [Breadth-First Search](https://www.internhack.in/learn/dsa/breadth-first-search) (245)
- [Bit Manipulation](https://www.internhack.in/learn/dsa/bit-manipulation) (238)
- [Tree](https://www.internhack.in/learn/dsa/tree) (235)
- [Two Pointers](https://www.internhack.in/learn/dsa/two-pointers) (217)
- [Prefix Sum](https://www.internhack.in/learn/dsa/prefix-sum) (204)
- [Database](https://www.internhack.in/learn/dsa/database) (197)
- [Heap (Priority Queue)](https://www.internhack.in/learn/dsa/heap-priority-queue) (196)
- [Simulation](https://www.internhack.in/learn/dsa/simulation) (177)
- [Counting](https://www.internhack.in/learn/dsa/counting) (174)
- [Binary Tree](https://www.internhack.in/learn/dsa/binary-tree) (169)

## Related

- [Home](https://www.internhack.in/)
- [Learn](https://www.internhack.in/learn)
- [DSA](https://www.internhack.in/learn/dsa)
