dsa2 min read
Random Pick Index — Reservoir Sampling
Pick a random index of a target value with equal probability using reservoir sampling over the array.
Read →
webcoderspeed.com
1276 articles
Pick a random index of a target value with equal probability using reservoir sampling over the array.
Find the most common word not in a banned list by normalizing input and using a frequency counter.
Determine if cards can be rearranged into consecutive groups of size groupSize using a sorted frequency map.
Count subarrays with sum divisible by k using prefix mod frequencies and the complement map pattern.
Count pairs summing to a power of 2 by checking all 22 powers-of-2 against a running frequency map.