LeetCode 973: K Closest Points to Origin
A clear explanation of returning the k closest points to the origin using squared distance and sorting.
153 notes
A clear explanation of returning the k closest points to the origin using squared distance and sorting.
A clear explanation of comparing rational numbers written as decimal strings with optional repeating parts.
A clear explanation of generating all powerful integers using bounded powers and a set.
A clear explanation of expressing a target using the fewest operators with repeated uses of x.
A clear explanation of finding the minimum-area rectangle from points when the rectangle may be rotated.
A clear explanation of solving Largest Component Size by Common Factor using prime factorization and union find.
A clear explanation of the New 21 Game problem using probability dynamic programming and a sliding window sum.
A clear explanation of the Rectangle Overlap problem using axis projections and positive intersection area.
A clear explanation of the Consecutive Numbers Sum problem using arithmetic series formulas and divisibility analysis.
A clear explanation of counting valid music playlists using dynamic programming over playlist length and unique songs used.
A clear explanation of checking whether card counts share a common group size using the greatest common divisor.
A clear explanation of minimizing an array score after each value can move by at most k.
A clear explanation of counting super-palindromes by generating palindromic roots and checking their squares.
A clear explanation of counting numbers less than or equal to N using digit-by-digit construction and combinatorics.
A clear explanation of finding the lexicographically smallest string after queue operations using rotation and sorting.
A clear explanation of computing the exposed surface area of stacked cubes by adding tower area and subtracting shared faces.
A clear explanation of summing subsequence widths by sorting and counting each element as a maximum and minimum.
A clear explanation of finding one candy box swap that makes Alice and Bob have equal total candies.
A clear explanation of finding the minimum worst-case number of moves using dynamic programming over eggs and moves.
A clear explanation of finding the kth character in a decoded string without building the full decoded string.
A clear explanation of finding the nth magical number using binary search, greatest common divisor, least common multiple, and inclusion-exclusion.
A clear explanation of Minimum Factorization using greedy digit factors from 9 down to 2.
A clear explanation of finding the minimum operations by working backward from target to startValue.
A clear explanation of adding an integer to an array-form number using digit-by-digit simulation.
A clear explanation of checking whether the digits of a number can be reordered to form a power of two using digit frequency signatures.
A clear explanation of finding the smallest prime palindrome greater than or equal to n by generating odd-length palindromes and testing primality.
A clear explanation of Mirror Reflection using room unfolding, least common multiples, and parity.
A clear explanation of solving Beautiful Array using divide and conquer with odd and even transformations.
A dynamic programming solution for finding the shortest instruction sequence that drives a race car to the target position.
A geometry solution for finding the largest triangle area by checking every triplet of points with the cross product formula.
A math and bit manipulation solution for deciding whether Alice wins the XOR removal game.
A dynamic programming solution for deciding whether an array can be split into two non-empty groups with the same average.
A clear explanation of finding the closest shorthand RGB color by rounding each color channel to the nearest repeated hexadecimal pair.
A clear explanation of finding how many integers have exactly k trailing zeroes in their factorial.
A clear explanation of counting tilings of a 2 x n board using dominoes and L-shaped trominoes with dynamic programming.
A clear explanation of deciding whether escape is possible by comparing Manhattan distances to the target.
A clear explanation of counting good numbers after rotating every digit by 180 degrees.
A clear explanation of transforming a binary board into a chessboard using feasibility checks and minimum row and column swaps.
A clear explanation of finding the minimum possible number of rabbits using counting and greedy grouping.
A clear explanation of checking whether one point can reach another by working backward with modulo.
A clear explanation of finding the kth symbol in the grammar sequence using recursion and the parent-child relationship.
A clear explanation of checking whether every global inversion is also a local inversion using distance constraints.
A clear explanation of simplifying algebraic expressions by parsing, substituting variables, and combining polynomial terms.
A clear explanation of counting numbers whose binary representation has a prime number of set bits.
A clear explanation of reaching a target on a number line using cumulative sums and parity.
A clear explanation of selecting a uniformly random integer while excluding blacklisted values using remapping and hashing.
Find the largest number less than or equal to n whose digits are monotone increasing using a greedy digit adjustment.
Check each number in a range by extracting its digits and testing whether every digit divides the original number.
Determine whether four numbers can be combined with arithmetic operations and parentheses to produce 24.
A clear explanation of counting possible bulb states after pressing four toggle buttons exactly presses times.
A clear explanation of maximizing an integer by swapping at most two digits once.
A clear explanation of finding the kth smallest value in an m by n multiplication table using binary search on answer.
A dynamic programming solution for maximizing the number of A characters printed with a limited number of keyboard operations.
A dynamic programming and prime factorization solution for finding the minimum operations needed to produce n characters.
A counting and math solution for finding the duplicated number and the missing number in a corrupted set.
A string parsing solution for reducing a linear equation into coefficient and constant terms.
A dynamic programming and combinatorics solution for counting permutations with no fixed positions.
A two-pointer and number theory solution for checking whether an integer can be written as the sum of two square numbers.
A dynamic programming solution for counting permutations of 1 to n with exactly k inverse pairs.
A clear explanation of finding the largest product of three numbers using sorting or constant-space tracking.
A detailed explanation of counting how many times digit one appears from 0 to n using positional digit analysis.
A clear explanation of determining whether an integer is a power of two using binary properties and bit manipulation.
A detailed explanation of evaluating arithmetic expressions with stack-based parsing and operator precedence.
A clear explanation of Pow(x, n) using binary exponentiation to compute powers in logarithmic time.
A clear explanation of Rotate Image using in-place matrix transpose and row reversal.
A clear explanation of Multiply Strings using grade-school multiplication with digit arrays.
A clear explanation of finding the nth positive integer that does not contain the digit 9 using base-9 conversion.
A SQL guide for finding the minimum Euclidean distance between any two points in a 2D plane.
A SQL guide for checking whether three side lengths can form a valid triangle using the triangle inequality.
A clear math solution for counting the maximum values after repeated top-left matrix increment operations.
A clear geometry solution for checking whether four unordered points form a valid square.
A clear parsing and math solution for evaluating fraction addition and subtraction expressions.
A clear explanation of Squirrel Simulation using Manhattan distance and the special first trip.
A clear explanation of Find the Closest Palindrome using prefix mirroring and a small candidate set.
A clear explanation of Next Greater Element III using the next permutation algorithm on the digits of an integer.
A clear explanation of Optimal Division using the structure of division expressions to build the maximum-value expression.
A clear explanation of multiplying complex numbers represented as strings using algebraic expansion.
A clear explanation of detecting a subarray whose sum is a multiple of k using prefix sums and modular arithmetic.
A clear explanation of computing Fibonacci numbers using dynamic programming and iterative state transitions.
A clear explanation of checking whether a number equals the sum of its positive divisors excluding itself.
A clear explanation of converting an integer into its base 7 string representation using repeated division.
A clear explanation of finding rectangle dimensions with a fixed area and the smallest length-width difference.
A clear explanation of finding the smallest base where n is written as all ones using geometric series and binary search.
A clear explanation of finding the largest palindrome made from the product of two n-digit numbers by generating palindrome candidates directly.
A clear explanation of generating uniformly random points inside a circle using polar coordinates.
A clear explanation of generating a uniform random integer from 1 to 10 using only rand7 and rejection sampling.
A clear explanation of checking whether ordered points form a convex polygon using cross products.
A clear explanation of why the median minimizes the number of moves needed to make all array elements equal.
A clear explanation of the combinatorics behind finding the minimum number of pigs needed to identify the poisonous bucket.
A clear explanation of the math behind making all array elements equal by incrementing n - 1 elements at a time.
Count ordered boomerang tuples by fixing each point as the center and grouping other points by squared distance.
Add two numbers stored in forward-order linked lists using stacks and carry propagation.
Find the maximum number of complete staircase rows that can be formed using binary search and triangular numbers.
Find the k-th integer in lexicographical order without generating all numbers, using prefix counting over a conceptual trie.
A clear explanation of adding two non-negative integer strings using manual digit-by-digit simulation.
A clear explanation of counting arithmetic subarrays using dynamic programming and consecutive differences.
A clear explanation of the Fizz Buzz problem using direct simulation and divisibility checks.
A clear explanation of converting integers to hexadecimal using bit manipulation and two's complement representation.
A clear explanation of finding the nth digit in the infinite integer sequence using digit groups and arithmetic.
A clear explanation of picking a uniformly random index for a target value using reservoir sampling, with an alternative hash map approach.
A clear explanation of reducing an integer to 1 with the fewest operations using greedy bit decisions.
A clear explanation of maximizing the rotation function using a recurrence instead of simulating every rotation.
A clear explanation of finding the last remaining number after alternating left-to-right and right-to-left eliminations.
A clear explanation of shuffling an array uniformly using the Fisher-Yates algorithm while supporting reset.
A clear explanation of selecting a random linked list node with equal probability using reservoir sampling.
A clear explanation of computing large modular exponentiation using fast power, modular arithmetic, and digit decomposition.
A clear explanation of adding two integers without using plus or minus by using XOR, AND, carry, and a 32-bit mask.
A clear explanation of adding one to a number stored as a linked list using the rightmost non-nine digit.
A clear explanation of finding the largest subset where every pair is divisible using sorting, dynamic programming, and parent reconstruction.
A clear explanation of checking whether an integer is a perfect square using binary search without sqrt.
A clear explanation of solving the Water and Jug Problem using Bézout's identity and greatest common divisor.
A clear explanation of sorting values after applying a quadratic function using two pointers.
A clear explanation of counting numbers with unique digits using combinatorics.
A clear explanation of Integer Break using dynamic programming, with a note on the greedy math solution.
A clear explanation of Power of Four using bit manipulation and binary properties.
A clear explanation of Self Crossing using constant-space checks for the only possible crossing patterns.
A clear explanation of the Power of Three problem using repeated division and integer arithmetic.
A clear explanation of Bulb Switcher using divisor parity and perfect squares.
A clear explanation of Super Ugly Number using dynamic programming with one pointer per prime.
A median-based solution for minimizing total Manhattan distance in a grid.
A game theory solution for deciding whether the first player can win by using the losing-position pattern of multiples of four.
A dynamic programming solution for finding the least number of perfect square numbers that sum to n.
A clear explanation of the Integer to English Words problem using three-digit chunks and scale words.
A clear explanation of the Missing Number problem using sum formula and XOR.
A clear explanation of the Ugly Number II problem using dynamic programming with three pointers.
A clear explanation of the Ugly Number problem using repeated division by the only allowed prime factors.
A clear explanation of the Add Digits problem using repeated digit sums first, then the digital root formula.
A clear explanation of the Factor Combinations problem using DFS backtracking with non-decreasing factors.
A clear explanation of computing the total covered area of two axis-aligned rectangles by subtracting their overlap.
A clear explanation of counting prime numbers less than n using the Sieve of Eratosthenes.
A clear explanation of detecting whether repeated digit-square sums eventually reach 1.
A detailed guide to solving Unique Binary Search Trees with dynamic programming and the Catalan recurrence.
A detailed guide to solving Gray Code using the binary-to-Gray-code formula.
A clear explanation of converting an Excel column title into its numeric index using base 26 accumulation.
A clear explanation of converting a positive integer into an Excel column title using bijective base 26.
A clear explanation of converting a fraction into decimal form and detecting repeating fractional parts with a hash map.
Evaluate an arithmetic expression written in Reverse Polish Notation using a stack.
Find the maximum number of points lying on the same straight line using slope counting and normalization.
Find the node where a linked list cycle begins using Floyd’s tortoise and hare algorithm with cycle entry mathematics.
A clear explanation of generating a single row of Pascal's Triangle using in-place dynamic programming.
A clear explanation of generating Pascal's Triangle row by row using dynamic programming.
A clear guide to counting distinct ways to climb stairs using dynamic programming.
A clear guide to computing the integer square root using binary search without built-in exponent functions.
A clear guide to adding two binary strings using two pointers and a carry.
A clear guide to adding one to a large integer represented as an array of digits.
A clear guide to finding the kth permutation sequence using factorial blocks instead of generating all permutations.
A clear explanation of integer division without using multiplication, division, or modulo, using repeated doubling with bit shifts.
A detailed explanation of converting a Roman numeral string into an integer using symbol values and the subtraction rule.
A detailed explanation of converting an integer into a Roman numeral using a fixed value-symbol table and greedy subtraction.
A detailed explanation of checking whether an integer is a palindrome using digit operations without converting it to a string.
A detailed explanation of reversing a signed 32-bit integer while handling overflow correctly.
A detailed explanation of the Add Two Numbers linked list problem, including digit-by-digit addition, carry handling, and linked list construction.
A clear explanation of counting trailing zeroes in n! by counting factors of 5 instead of computing the factorial directly.