dsa1 min read
Subarray Sum Equals K [Medium] — Prefix Sum HashMap
Count subarrays with sum exactly k using prefix sums stored in a HashMap to find valid starting positions in O(n).
Read →
webcoderspeed.com
1276 articles
Count subarrays with sum exactly k using prefix sums stored in a HashMap to find valid starting positions in O(n).
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.