Pattern
Math
A compact view of archive entries grouped by recurring technique.
75 entries
75 entries tagged as Math.
24.04.2026
easy2833. Furthest Point From Origin
Max dist when replace with L or R
09.04.2026
hard3655. XOR After Range Multiplication Queries II
Run stepped multiplication queries
24.03.2026
medium2906. Construct Product Matrix
Product of other cells in a matrix
21.02.2026
easy762. Prime Number of Set Bits in Binary Representation
Number in l..r with prime bits count
20.01.2026
easy3314. Construct the Minimum Bitwise Array I
Reverse x | (x+1) operation on prime numbers
04.12.2025
medium1390. Four Divisors
Sum of exactly four-divisors of each number
03.12.2025
hard3625. Count Number of Trapezoids II
Count trapezoids from points
12.11.2025
medium2654. Minimum Number of Operations to Make All Array Elements Equal to 1
Min steps to make all '1' by gcd
24.09.2025
medium166. Fraction to Recurring Decimal
Calc a/b to string x.y(z)
16.09.2025
hard2197. Replace Non-Coprime Numbers in Array
Simulate gcd to lcm adjacent pair removal
06.09.2025
hard3495. Minimum Operations to Make Array Elements Zero
Sum query [a..b] of optimal pairwise /4 until range is zero
03.09.2025
hard3027. Find the Number of Ways to Place People II
Left-top, bottom-right pairs with empty rectangles
29.08.2025
medium3021. Alice and Bob Playing Flower Game
Pairs x=1..n y=1..m for Alice to win in take from (x+y) game
18.08.2025
hard679. 24 Game
Can a,b,c,d = 24 with ops /+-()
17.08.2025
medium837. New 21 Game
Probability sum of random(1..m) less than n when stop adding at k
13.08.2025
easy326. Power of Three
Is n power of 3?
11.08.2025
medium2438. Range Product Queries of Powers
Range product queries of powers of two from n
23.06.2025
hard2081. Sum of k-Mirror Numbers
n palindromes in both 10 and k-base
17.06.2025
hard3405. Count the Number of Arrays with K Matching Adjacent Elements
Combinations k equal siblings 1..m in [n] array
01.06.2025
medium2929. Distribute Candies Among Children II
Ways to give limited from n candies to 3 kids
27.05.2025
easy2894. Divisible and Non-divisible Sums Difference
Sum non-divisible minus sum divisible
14.05.2025
hard3337. Total Characters in String After Transformations II
t steps to convert char into next nums[c] chars
09.05.2025
hard3343. Count Number of Balanced Permutations
Permutations of even-odd position sums equal
25.04.2025
medium2845. Count of Interesting Subarrays
Subarrays, count a[i]%m=k is c%m=k map
20.04.2025
medium781. Rabbits in Forest
Count total rabbits from other numbers
16.04.2025
medium2537. Count the Number of Good Subarrays
Subarrays with at least k equal pairs window
13.04.2025
medium1922. Count Good Numbers
Count (0,2,4,6,8)(2,3,5,7) generated strings of length n
12.04.2025
hard3272. Find the Count of Good Integers
Count palindromes of length n, divisible by k
10.04.2025
hard2999. Count the Number of Powerful Integers
Numbers in range start..finish, digits up to limit
05.04.2025
easy1863. Sum of All Subset XOR Totals
Sum of all subsets xors
29.03.2025
hard2818. Apply Operations to Maximize Score
Multiply k numbers with max prime factor count stack
26.03.2025
medium2033. Minimum Operations to Make a Uni-Value Grid
Min sum of differences of x times
07.03.2025
medium2523. Closest Prime Numbers in Range
Min diff primes pair in left..right
06.03.2025
easy2965. Find Missing and Repeated Values
Missing and repeated in 1..n array
05.03.2025
medium2579. Count Total Number of Colored Cells
Arithmetic sum
04.03.2025
medium1780. Check if Number is a Sum of Powers of Three
Number as the sum of distinct powers of 3
25.02.2025
medium1524. Number of Sub-arrays With Odd Sum
Count odd sum subarrays sum
19.02.2025
medium1415. The k-th Lexicographical String of All Happy Strings of Length n
kth string of abc permutations
14.02.2025
medium1352. Product of the Last K Numbers
Running suffix product product
11.11.2024
medium2601. Prime Subtraction Operation
Increased sequence by subtracting primes? search
28.10.2024
medium2501. Longest Square Streak in an Array
Longest quadratic subset
04.10.2024
medium2491. Divide Players Into Teams of Equal Skill
Sum of products of pairs with equal sums
03.10.2024
medium1590. Make Sum Divisible by P
Min removed subarray length to make remainder % p = 0
01.10.2024
medium1497. Check If Array Pairs Are Divisible by k
Can all pairs sums be k-even?
22.09.2024
hard440. K-th Smallest in Lexicographical Order
k lexicographically smallest value from 1..n
18.09.2024
medium179. Largest Number
Concatenate nums to largest number
10.09.2024
medium2807. Insert Greatest Common Divisors in Linked List
Insert gcd in-between LinkedList nodes list
05.09.2024
medium2028. Find Missing Observations
Find n numbers to make [n m]/(n+m)=mean
24.08.2024
hard564. Find the Closest Palindrome
Closest palindrome number
23.08.2024
easy592. Fraction Addition and Subtraction
Eval string of fractions sum
20.08.2024
medium1140. Stone Game II
Max Alice price taking 1..2m piles optimally with Bob programming
19.08.2024
medium650. 2 Keys Keyboard
Min copy-pastes to make n A's from one programming
8.07.2024
medium1823. Find the Winner of the Circular Game
Last of k-th excluded from 1..n
7.07.2024
easy1518. Water Bottles
Bottles drink and exchange simulation
6.07.2024
easy2582. Pass the Pillow
Loop position in increasing-decreasing array
19.05.2024
hard3068. Find the Maximum Sum of Node Values
Max sum after xor k any edges in a tree
13.04.2024
hard85. Maximal Rectangle
Max 1-only area in a 0-1 matrix
14.03.2024
medium930. Binary Subarrays With Sum
Count goal-sum subarrays in a 0-1 array
25.02.2024
hard2709. Greatest Common Divisor Traversal
Are all numbers connected through gcd?
20.02.2024
easy268. Missing Number
Missing in [0..n] number.
21.08.2023
easy459. Repeated Substring Pattern
careful to not shift by whole length
14.05.2023
hard1799. Maximize Score After N Operations
Max indexed-gcd-pair sum from 2n array; [3,4,6,8] -> 11 (1gcd(3,6) + 2gcd(4,8))
2.05.2023
easy1822. Sign of the Product of an Array
There is an sign function in kotlin, but leetcode.com doesn't support it yet.
02.04.2023
medium2300. Successful Pairs of Spells and Potions
sort potions
24.03.2023
medium1466. Reorder Routes to Make All Paths Lead to the City Zero
We can use data structure or just use sign to encode the direction.
21.03.2023
medium2348. Number of Zero-Filled Subarrays
We can count subarray sums, then add them to the result, or we can just skip directly to adding to the result.
03.03.2023
medium28. Find the Index of the First Occurrence in a String
carefull with indexes
24.02.2023
hard1675. Minimize Deviation in Array
Use TreeSet to quickly access to the min and max elements.
17.02.2023
easy783. Minimum Distance Between BST Nodes
Let's write Morris Traversal. Store current node at the rightmost end of the left children.
1.02.2023
easy1071. Greatest Common Divisor of Strings
We can first find the length of the greatest common divisor, then just check both strings.
8.01.2023
hard149. Max Points on a Line
fun maxPoints(points: Array
9.12.2022
medium1026. Maximum Difference Between Node and Ancestor
fun maxAncestorDiff(root: TreeNode?): Int {
22.11.2022
mediumPerfect Squares
val cache = mutableMapOf
18.11.2022
easyUgly Number
fun isUgly(n: Int): Boolean {
1.11.2022
mediumWhere Will The Ball Fall
This is a geometry problem, but seeing the pattern might help. We can spot that each row is an action sequence: -1 -1 -1 shifts balls left, and 1 1 1 shifts balls to the right. Corners can be formed only with -1 1 sequence.