number theory
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
Pattern Bridge
High-Pressure Round
Count Primes
Count all prime numbers less than a given integer n using efficient array and math-based enumeration techniques.
Add Digits
Add Digits involves repeatedly summing digits of a number until a single digit is obtained.
Mirror Reflection
Given a square room with mirrors, find which receptor a laser ray will hit first based on two integers, p and q.
Prime Palindrome
The Prime Palindrome problem asks for the smallest prime palindrome greater than or equal to a given integer.
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.
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 …
Ugly Number III
Find the nth positive integer divisible by a, b, or c using binary search over the answer space efficiently and accurate…
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 …
Simplified Fractions
Generate simplified fractions between 0 and 1 with denominators up to a given integer n.
The kth Factor of n
Find the kth factor of n by scanning divisors carefully or using factor pairs to skip unnecessary checks.
Graph Connectivity With Threshold
In 'Graph Connectivity With Threshold,' determine if cities are connected based on common divisors exceeding a threshold…
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…
Tree of Coprimes
Determine the closest coprime ancestor for each node in a tree using efficient traversal and state tracking of node valu…
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 …
Maximize Number of Nice Divisors
Solve Maximize Number of Nice Divisors by splitting primeFactors into mostly 3s and using fast modular exponentiation.
Number of Different Subsequences GCDs
Given an array of positive integers, find the number of different subsequences' GCDs.
Three Divisors
Determine if a given integer has exactly three positive divisors.
Find Greatest Common Divisor of Array
Find the greatest common divisor of the smallest and largest numbers in an integer array.
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.
GCD Sort of an Array
The GCD Sort problem challenges you to sort an array using a specific gcd-based swap method.
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.
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.
Replace Non-Coprime Numbers in Array
Replace Non-Coprime Numbers in Array uses stack-based state management to iteratively merge adjacent non-coprime integer…
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…
Count the Number of Ideal Arrays
This problem involves counting the number of ideal arrays of a given length under certain conditions using state transit…
Minimum Deletions to Make Array Divisible
Find the minimum number of deletions to make the smallest element in nums divide all elements of numsDivide.
Smallest Even Multiple
Find the smallest even multiple of a given integer using math and number theory concepts efficiently.
Number of Common Factors
The problem asks to find the number of common factors of two positive integers a and b.
Number of Subarrays With GCD Equal to K
Count the number of subarrays with GCD equal to a given value k from a list of integers.
Number of Subarrays With LCM Equal to K
Find the number of subarrays in an array where the least common multiple (LCM) of the subarray equals a given integer k.
Smallest Value After Replacing With Sum of Prime Factors
Replace a number with the sum of its prime factors until it stabilizes, and return the smallest value.
Minimize the Maximum of Two Arrays
Minimize the Maximum of Two Arrays requires finding the smallest possible maximum number across two arrays, using binary…
Distinct Prime Factors of Product of Array
Find the number of distinct prime factors in the product of an array of integers.
Closest Prime Numbers in Range
Find the two closest prime numbers within a given range using efficient number theory techniques and gap comparisons.
Check if Point Is Reachable
Determine if a target point is reachable from (1,1) using math-based moves following number theory rules efficiently.
Split the Array to Make Coprime Products
Find the smallest index to split an array so that the products of two parts are coprime using array scanning and hash lo…
Prime Subtraction Operation
Determine if it's possible to make the array strictly increasing using prime subtractions.
Make K-Subarray Sums Equal
Solve Make K-Subarray Sums Equal by grouping circular indices with gcd cycles and minimizing each group to its median.
Prime In Diagonal
Find the largest prime number located on any diagonal of a square matrix using array iteration and prime checking techni…
Minimum Number of Operations to Make All Array Elements Equal to 1
Find the minimum number of operations to transform every element of a positive integer array into 1 using gcd operations…
Greatest Common Divisor Traversal
Determine if every index in an array can be reached from any other using traversals based on greatest common divisors.
Number of Beautiful Pairs
Count all index pairs in an array where the first digit of one number and last digit of another are coprime efficiently.
Prime Pairs With Target Sum
Find all prime number pairs that sum up to a given integer n using an efficient sieve-based array approach.
Insert Greatest Common Divisors in Linked List
The problem involves inserting greatest common divisors between adjacent nodes in a linked list.
Apply Operations to Maximize Score
Maximize the score by applying operations on a subarray at most k times, utilizing stack-based state management.
Maximum Element-Sum of a Complete Subset of Indices
Given a 1-indexed array, select a subset where indices' product is a perfect square, then return the maximum sum.
Count Valid Paths in a Tree
Count Valid Paths in a Tree involves finding paths with exactly one prime number in a tree of n nodes.
Count Beautiful Substrings I
Given a string and a value k, count the number of beautiful substrings where vowels * consonants % k == 0.
Count Beautiful Substrings II
Count Beautiful Substrings II focuses on finding beautiful substrings with hash tables and number theory techniques.
Minimize Length of Array Using Operations
Minimize the length of an integer array through a series of operations, using a greedy approach with modular arithmetic.
Most Frequent Prime
Find the most frequent prime over 10 from numbers generated by scanning a 2D matrix in all straight directions efficient…
Maximum Prime Difference
Calculate the largest index gap between prime numbers in an array using array traversal and number theory insights effic…
Kth Smallest Amount With Single Denomination Combination
Find the kth smallest amount using only one coin denomination at a time, applying binary search efficiently over possibl…
Find the Count of Numbers Which Are Not Special
Count the numbers between two integers that are not special, where special numbers are squares of primes.
Find the Largest Palindrome Divisible by K
Compute the largest n-digit integer divisible by k that forms a palindrome using state transition dynamic programming te…
Sorted GCD Pair Queries
Solve the Sorted GCD Pair Queries problem by efficiently counting and locating GCDs of all array pairs using hash mappin…
Minimum Division Operations to Make Array Non Decreasing
Determine the minimum number of division operations to make an array non-decreasing using a greedy and invariant-based s…
Find the Maximum Factor Score of Array
Calculate the maximum factor score of an integer array by optionally removing one element using LCM and GCD computations…
Find the Number of Subsequences With Equal GCD
Count all pairs of non-empty subsequences in an integer array whose elements share the same greatest common divisor effi…
Smallest Divisible Digit Product II
Find the smallest zero-free number at least as large as num whose digits multiply to a product divisible by t using care…
Digit Operations to Make Two Integers Equal
Transform n into m using allowed digit operations without creating primes, applying math and graph strategies efficientl…
Count Connected Components in LCM Graph
Determine the number of connected components in an LCM-based graph using array scanning and hash-based connectivity chec…
Maximum Subarray With Equal Products
This problem involves finding the longest subarray where the product equals the LCM multiplied by the GCD, leveraging a …
Minimum Increments for Target Multiples in an Array
This problem involves incrementing elements of an array to make sure each target element has at least one multiple in th…
Check If Digits Are Equal in String After Operations I
Simulate repeated adjacent digit sums modulo 10 until two digits remain, then check whether those final digits match.
Check If Digits Are Equal in String After Operations II
Determine if repeated digit-sum operations on a numeric string reduce it to two equal digits using math and string techn…
Sum of Largest Prime Substrings
Compute the sum of the three largest unique primes from all substrings using hash table plus math efficiently.
Maximize Count of Distinct Primes After Split
Compute the maximum number of distinct prime numbers after sequentially updating array elements with efficient preproces…
Maximize Subarray GCD Score
Maximize Subarray GCD Score focuses on maximizing a subarray's score by using at most k doubling operations on an array …
Count Prime-Gap Balanced Subarrays
Count the number of prime-gap balanced subarrays in an integer array using sliding window techniques and running state u…
Check if Any Element Has Prime Frequency
Check if any element in the array has a prime frequency count, leveraging array scanning and hash table lookup.
Minimum Stability Factor of Array
The problem requires finding the minimum stability factor of an array by utilizing binary search and math-based optimiza…
Split Array by Prime Indices
Split Array by Prime Indices challenges you to separate elements at prime positions and minimize the absolute sum differ…