↓Skip to main content

Math

LeetCode 2235: Add Two Integers
·1 min
LeetCode Easy Math
LeetCode 2235 note: return the sum; the C++ version once failed to compile from a missing semicolon
LeetCode 3697: Compute Decimal Representation
·1 min
LeetCode Easy Math Array
LeetCode 3697 note: each non-zero digit times its place value is one component; output them from the highest place down
LeetCode 3649: Number of Perfect Pairs
·2 mins
LeetCode Medium Two-Pointers Math Sorting Array
LeetCode 3649 note: simplify the condition to “larger absolute value <= 2 × smaller absolute value”, then count with two pointers over sorted absolute values
LeetCode 3648: Minimum Sensors to Cover Grid
·2 mins
LeetCode Medium Math
LeetCode 3648 note: each sensor covers a (2k + 1) × (2k + 1) square, so take a ceiling division in each direction and multiply
LeetCode 150: Evaluate Reverse Polish Notation
·2 mins
LeetCode Daily Medium Stack Data-Structures Expression-Evaluation Math Postfix-Notation Reverse-Polish-Notation
Solving the Reverse Polish Notation evaluation problem using stack-based approach
LeetCode 1497: Check If Array Pairs Are Divisible by k (Remainder Pairing, Modulo)
·2 mins
LeetCode Daily Medium Array Hash-Map Complement Counting Math Modulo
Remainder pairing with a hash map; handle 0 and k/2 remainders carefully.
LeetCode 1071: Greatest Common Divisor of Strings
·2 mins
LeetCode Daily Easy String Gcd Math
LeetCode Problem Solving
LeetCode 2709: Greatest Common Divisor Traversal
·3 mins
LeetCode Hard Math Number-Theory Union-Find Sieve Gcd Array
LeetCode 2709 note: every pair of indices connects ⇔ one component; factor with SPF and union each number with its prime factors in Union-Find, treating 1 specially
LeetCode 3627: Maximum Median Sum of Subsequences of Size 3
·2 mins
LeetCode Medium Math Greedy Sorting Game-Theory Array
LeetCode 3627 note: after sorting, each group takes the two largest and the smallest, with the second largest as the median; the answer takes every other value from the end, n / 3 of them
LeetCode 2745: Construct the Longest New String
·2 mins
LeetCode Medium Dynamic-Programming Math Greedy Brainteaser
LeetCode 2745 note: AA and BB must alternate, using min(x, y) pairs plus one extra of the more common kind, and every AB fits in
LeetCode 1304: Find N Unique Integers Sum up to Zero
·1 min
LeetCode Easy Math Array
LeetCode 1304 note: place 1..n/2 and their negatives so each pair cancels, adding 0 when n is odd
LeetCode 3622: Check Divisibility by Digit Sum and Product
·1 min
LeetCode Easy Math
LeetCode 3622 note: compute the digit sum and product and test n % (sum + product) == 0, keeping the modulo the right way around