Prefix-sum

24 articles

dsa13 min read

Subarray Sum Equals K — Why Prefix Sum + HashMap Beats Everything [LC 560]

LeetCode 560 is one of the most-asked FAANG problems because it teaches the prefix sum + hashmap pattern — a technique that handles negative numbers, generalizes to a dozen follow-ups, and cannot be replaced by sliding window. Learn the insight, the dry run, the common mistakes, and the O(n) solution in Python and JavaScript.

Read →