dsa2 min read
Shuffle an Array — Fisher-Yates O(n) Uniform Shuffle [Google Easy]
Implement Fisher-Yates shuffle for uniform random permutation. Every arrangement is equally probable. O(n) time O(1) extra space.
Read →
webcoderspeed.com
1276 articles
Implement Fisher-Yates shuffle for uniform random permutation. Every arrangement is equally probable. O(n) time O(1) extra space.
Compute running (prefix) sum in O(n) time O(1) extra space. The prefix sum pattern is foundational for range queries, subarray problems and 2D matrices.
Find all unique triplets summing to zero. Sort array then fix one element and use two pointers. Full O(n²) solution in C, C++, Java, JavaScript and Python.
Find two lines that together with the x-axis form a container holding the most water. Greedy two-pointer O(n) — never check a pair that can't be optimal.
Compute product of all elements except self without division. O(n) two-pass prefix/suffix approach with O(1) extra space.