dsa1 min read
Continuous Subarray Sum [Medium] — Prefix Modulo Map
Check if a continuous subarray of length >= 2 sums to a multiple of k using prefix sum modulo k with a HashMap.
Read →
1575 articles
Check if a continuous subarray of length >= 2 sums to a multiple of k using prefix sum modulo k with a HashMap.
Find the longest consecutive integer sequence in O(n) by using a HashSet and only starting sequences from their minimum element.
Design a set with O(1) insert, delete, and getRandom using a dynamic array combined with a HashMap for index tracking.
Find all starting indices of anagram substrings by using a fixed window with character frequency comparison.
Implement weighted random selection by building a prefix sum array and using binary search to find the sampled index.