LeetCode 528: Random Pick with Weight
A clear explanation of weighted random sampling using prefix sums and binary search.
15 notes
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 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 picking a uniformly random index for a target value using reservoir sampling, with an alternative hash map approach.
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 designing a randomized multiset with average O(1) insert, remove, and getRandom operations.
A clear explanation of designing a randomized set with average O(1) insert, remove, and getRandom operations.
Generate a uniform random permutation of an array in-place.
Quicksort variant that selects pivots randomly to avoid worst case patterns.
Select k distinct integers uniformly from a fixed range without shuffling the whole range.
Select a random sample from a stream where each item has a nonnegative weight.
Select a uniform random sample from a stream of unknown length using fixed memory.
Quickselect with random pivot selection to achieve robust expected linear time.