LeetCode 911: Online Election
A clear explanation of Online Election using preprocessing and binary search over vote times.
91 notes
A clear explanation of Online Election using preprocessing and binary search over vote times.
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 nth magical number using binary search, greatest common divisor, least common multiple, and inclusion-exclusion.
A clear explanation of designing a time-based key-value store using a hash map and binary search.
A clear explanation of finding the minimum banana-eating speed using binary search on the answer.
A clear explanation of simulating an exam room by maintaining occupied seats in sorted order.
A clear explanation of finding the peak index in a mountain array using binary search.
A clear explanation of finding how many integers have exactly k trailing zeroes in their factorial.
A clear explanation of minimizing the largest adjacent gas-station distance using binary search on the answer.
A clear explanation of finding the kth smallest pair distance using sorting, binary search on the answer, and a two-pointer count.
A clear explanation of designing a range module that can add, query, and remove half-open intervals.
A clear explanation of searching for a target in a sorted array using binary search.
A clear explanation of searching in a sorted array when the array length is hidden behind an ArrayReader interface.
Use binary search to find the smallest character strictly greater than the target with wraparound handling.
A clear explanation of finding the kth smallest value in an m by n multiplication table using binary search on answer.
A clear explanation of finding the k closest elements to a target using binary search and a sliding window.
A binary search solution for finding the maximum average of any contiguous subarray with length at least k.
A two-pointer and number theory solution for checking whether an integer can be written as the sum of two square numbers.
A two-pointer guide for counting triplets that can form valid triangles after sorting the side lengths.
A clear explanation of searching a row-sorted and column-sorted matrix using the top-right corner elimination method.
A clear explanation of finding the only non-duplicate element in a sorted array using binary search.
A clear explanation of weighted random sampling using prefix sums and binary search.
A clear explanation of uniformly picking an integer point from non-overlapping rectangles using prefix sums and binary search.
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 minimum heater radius by sorting positions and matching each house to its nearest heater.
Find the maximum number of complete staircase rows that can be formed using binary search and triangular numbers.
Find, for each interval, the interval with the smallest start point greater than or equal to its end point using sorting and binary search.
A clear explanation of minimizing the largest subarray sum using binary search on the answer and greedy validation.
A clear explanation of finding the nth digit in the infinite integer sequence using digit groups and arithmetic.
A clear explanation of finding the kth smallest value in a row-sorted and column-sorted matrix using binary search on values.
A clear explanation of finding the picked number using binary search and the guess API.
A clear explanation of checking whether an integer is a perfect square using binary search without sqrt.
A clear explanation of reducing a 2D rectangle problem to a 1D prefix-sum problem with binary search.
A clear explanation of solving Russian Doll Envelopes using sorting and longest increasing subsequence.
A clear explanation of maintaining disjoint sorted intervals from a stream using insertion and merging.
A clear explanation of Smallest Rectangle Enclosing Black Pixels using binary search on rows and columns.
A dynamic programming and patience sorting solution for finding the longest strictly increasing subsequence in an array.
A binary-search-style solution for finding the smallest node greater than p in a binary search tree.
A binary search solution for finding the first bad version while minimizing calls to the isBadVersion API.
A clear explanation of the H-Index II problem using binary search on a sorted citations array.
A clear explanation of the Closest Binary Search Tree Value problem using the BST property to walk toward the target.
A clear explanation of counting nodes in a complete binary tree faster than visiting every node.
A detailed guide to solving Search in Rotated Sorted Array II with modified binary search and duplicate handling.
A clear explanation of finding two numbers in a sorted array using two pointers and constant extra space.
A clear explanation of finding any peak element using binary search on the slope of the array.
A clear explanation of finding the minimum element in a rotated sorted array that may contain duplicates.
A clear explanation of finding the minimum element in a rotated sorted array using binary search.
A clear guide to searching a sorted 2D matrix using binary search over a virtual one-dimensional array.
A clear guide to computing the integer square root using binary search without built-in exponent functions.
A clear explanation of finding the index of a target, or where it should be inserted, using binary search.
A clear explanation of finding the first and last index of a target in a sorted array using two binary searches.
A clear explanation of searching a rotated sorted array in logarithmic time using modified binary search.
A detailed explanation of finding the median of two sorted arrays using binary search over partitions.
Use interpolation to estimate the target position, with binary search fallback when estimates become unreliable.
Arrange and search sorted data with explicit knowledge of cache lines or memory blocks.
Search a binary tree stored in recursive cache oblivious layout to reduce memory transfers.
Binary search over an array arranged in heap order to improve cache locality and branch predictability.
Perform binary search with conditional moves or arithmetic updates instead of unpredictable branches.
Find the k-th smallest sum among all contiguous subarrays, usually for nonnegative arrays.
Find the k-th smallest absolute difference among all pairs in an array.
Select the k-th smallest element from a matrix whose rows and columns are sorted.
Answer offline connectivity queries by combining parallel binary search with a disjoint set union.
Binary search and its ordered-search relatives: interpolation, Fibonacci, rotated-array, matrix, parametric, and offline variants.
Use vector instructions to evaluate multiple candidate positions in a binary search step.
Compute lower bound using arithmetic or conditional moves instead of branches.
Insertion sort that uses binary search to find the insertion position, reducing comparisons.
Select the k-th smallest fraction formed by pairs from a sorted array using heap or binary search.
Select the k-th smallest element from two sorted arrays without merging them.
Search a sorted array by repeatedly halving the search interval.
Find the last position where a monotone predicate remains true.
Find the range of indices containing all occurrences of a value in a sorted array.
Find the first index where elements become strictly greater than a given value.
Compute the floor of the square root of a nonnegative integer using binary search.
Find the boundary where a Boolean predicate changes value over an ordered domain.
Find a root of a continuous function by repeatedly halving an interval where the function changes sign.
Answer many monotone queries by processing them together after all input is known.
Answer many offline queries by searching their answers simultaneously with shared checks.
Search for a boundary by trying decreasing jumps whose lengths are powers of two.
Speed up repeated binary searches across related sorted lists by linking sampled elements between lists.
Search a row-major sorted matrix by treating it as a virtual sorted array.
Find an element that is at least as large as its immediate neighbors.
Search a value in an array that first increases and then decreases.
Find the smallest element in a sorted array that has been rotated around an unknown pivot.
Search a value in a sorted array that has been rotated around an unknown pivot.
Binary search variant that uses precomputed step sizes instead of dynamic midpoint calculation.
Locate a search interval by exponential growth, then apply binary search.
Find an optimal value by binary searching a monotone feasibility condition.
Find the first position where a monotone predicate becomes true.
Find the first position where a value can be inserted without violating sorted order.
Binary search implemented using recursion over a shrinking interval.
Binary search implemented using a loop without recursion.