dsa1 min read
Random Pick with Weight [Medium] — Prefix Sum + Binary Search
Implement weighted random selection by building a prefix sum array and using binary search to find the sampled index.
Read →
webcoderspeed.com
1276 articles
Implement weighted random selection by building a prefix sum array and using binary search to find the sampled index.
Find the vertical line that crosses the fewest bricks by counting the most frequent gap position using a HashMap.
Check if all value frequencies are unique using two hash sets in O(n).
Count substrings with at most one odd-frequency letter using bitmask prefix XOR and a hash map.
Count (row, col) pairs that are equal by hashing each row tuple and each column tuple.