Meta — Subarray Sum Equals K (Prefix Sum + HashMap)
Count subarrays with sum equal to k using prefix sums and a hashmap. O(n) time by tracking how many times each prefix sum has occurred.
webcoderspeed.com
1276 articles
Count subarrays with sum equal to k using prefix sums and a hashmap. O(n) time by tracking how many times each prefix sum has occurred.
Find the k most frequent elements using a max-heap or bucket sort. O(n) bucket sort approach using frequency as bucket index — faster than O(n log n) heap.
Return the values visible from the right side of a binary tree — the last node of each BFS level. O(n) BFS with level tracking.
Comprehensive coverage of Two Sum, Two Sum II (sorted), 3Sum, and 4Sum. Amazon frequently tests these variants to gauge understanding of hashmap vs two-pointer trade-offs.
Return all ways to segment a string into dictionary words. Combines DP validity check with DFS+memo backtracking to avoid TLE on valid inputs.