LeetCode 66 looks trivial until you hit [9,9,9]. Learn why interviewers love this problem, how carry propagation cascades through digits, the critical all-9s edge case that requires a new array, and why early termination makes your solution elegant — with Python and JavaScript solutions fully explained.
March 19, 2026 Read →
Count the number of prime numbers strictly less than n. Master the Sieve of Eratosthenes — one of the most elegant algorithms in CS — with full code in C, C++, Java, JavaScript and Python.
March 19, 2026 Read →
Find the missing number in [0..n] using the Gauss sum formula or XOR in O(n) time O(1) space.
March 19, 2026 Read →
Find the minimum total moves to make all array elements equal by targeting the median value.
March 19, 2026 Read →
Find the maximum number of points on the same line using a slope-as-fraction HashMap for each anchor point.
March 19, 2026 Read →
Compute integer square root using right-boundary binary search to find the largest k where k*k <= x.
March 19, 2026 Read →
Maximize nums[index] given array length n, sum constraint maxSum, and each element >= 1 using binary search on the peak value.
March 19, 2026 Read →
Check if a number is a perfect square in O(log n) using binary search or by exploiting odd-number sum identity.
March 19, 2026 Read →
Find the minimum train speed to arrive on time given n rides (last ride doesn't wait) using binary search on speed.
March 19, 2026 Read →
Determine if a number is happy by repeatedly summing digit squares and detecting cycles using a HashSet or Floyd algorithm.
March 19, 2026 Read →
Convert a fraction to decimal string with recurring part detected via remainder position tracking.
March 19, 2026 Read →
Evaluate an RPN expression by pushing numbers and applying operators to the top two stack elements.
March 19, 2026 Read →
Calculate the score of balanced parentheses where () = 1 and AB = A+B and (A) = 2*A using a stack depth trick.
March 19, 2026 Read →
Complete reference for math and number theory DSA patterns: algorithm selection guide, complexity table, and top 25 interview problems.
April 29, 2025 Read →
Apply the inclusion-exclusion principle to count elements satisfying union of conditions. Solves divisibility, coverage, and derangement problems.
April 28, 2025 Read →
Master randomized DSA algorithms: reservoir sampling for streams, quickselect for O(n) kth element, and random shuffling.
April 27, 2025 Read →
Master combinatorial game theory: Nim XOR strategy, Grundy (nimber) values, and Sprague-Grundy theorem for composite games.
April 26, 2025 Read →
Tackle geometry problems in coding interviews: cross product, point-in-polygon, line intersection, and Graham scan convex hull.
April 25, 2025 Read →
Apply probability theory and expected value DP to competitive programming: dice problems, random walks, and geometric distribution.
April 24, 2025 Read →
Prevent integer overflow in competitive programming: safe multiplication, __int128, binary search on answers, and floating-point gotchas.
April 23, 2025 Read →
Build range query structures in O(sqrt n) per query with block decomposition. Simpler alternative to segment trees.
April 22, 2025 Read →
Solve systems of modular congruences with the Chinese Remainder Theorem. Fundamental for cryptography and competitive math.
April 21, 2025 Read →
Explore classic number sequences: Fibonacci, Lucas, Pell, tribonacci, with DP and matrix approaches.
April 20, 2025 Read →
Master bitwise operations for DSA: XOR tricks, Brian Kernighan bit counting, subset enumeration, and bitmask DP.
April 19, 2025 Read →
Solve linear recurrences like Fibonacci in O(log n) using matrix exponentiation. Essential for DP optimization on large n.
April 18, 2025 Read →
Explore digit manipulation, perfect/abundant numbers, Armstrong numbers, and common math interview patterns.
April 17, 2025 Read →
Compute combinations nCr efficiently with precomputed factorials, Pascal's triangle for small n, and Catalan numbers for tree/parenthesis counting.
April 16, 2025 Read →
Compute Euler's totient phi(n) for cryptography and modular inverse applications. Sieve variant for all values up to n.
April 15, 2025 Read →
Factor integers efficiently with trial division O(sqrt n), SPF sieve O(log n), and understand when each approach is optimal.
April 14, 2025 Read →
Master modular arithmetic for competitive programming: binary exponentiation O(log n), modular inverse, and Chinese Remainder Theorem.
April 13, 2025 Read →
Master GCD/LCM with Euclidean algorithm O(log n) and the Extended Euclidean for modular inverse computation.
April 12, 2025 Read →
Generate all primes up to n in O(n log log n) with the Sieve of Eratosthenes. Includes segmented sieve and prime factorization variants.
April 11, 2025 Read →
Master mathematical algorithms for DSA: primes, GCD, modular arithmetic, combinatorics, and fast exponentiation with 5-language implementations.
April 10, 2025 Read →
How to derive the OLS Estimator with matrix notation and a tour of math typesetting using markdown with the help of KaTeX.
December 21, 2020 Read →