Hot100: Subarray Sum Equals K Prefix Sum + Hash Map ACERS Guide

Subtitle / Summary This is Hot100 article #1 for the series: Subarray Sum Equals K. We reduce the naive O(n^2) approach to O(n) with prefix sum plus a frequency hash map, then map the same pattern to real engineering scenarios. Reading time: 12-15 min Tags: Hot100, prefix sum, hash map SEO keywords: Subarray Sum Equals K, prefix sum, hash map, O(n), Hot100 Meta description: O(n) counting of subarrays with sum k using prefix sum + hash map, with complexity analysis and runnable multi-language code. Target Readers Hot100 learners who want stable reusable templates Intermediate engineers who want to transfer counting patterns to real data pipelines Interview prep readers who want to master prefix sum + hash map Background / Motivation “Count subarrays whose sum equals k” is one of the most classic counting problems. It appears in log analytics, risk threshold hits, and transaction sequence statistics. The two-loop brute force method is straightforward, but slows down quickly as input grows. So we need an O(n) method that scales. ...

February 9, 2026 · 9 min · map[name:Jeanphilo]

Path Sum III: Prefix Sum + Hash Map Counting Downward Paths (LeetCode 437) ACERS Guide

Subtitle / Summary The constraint “the path can start anywhere, but must go downward” makes root-to-leaf DP insufficient. This ACERS guide explains prefix sums on trees: convert any downward path into a difference of two prefix sums, maintain a frequency hash map during one DFS, and finish in O(n). Reading time: 12–15 min Tags: binary tree, prefix sum, DFS, hash map SEO keywords: Path Sum III, tree prefix sum, prefix-sum hash, LeetCode 437 Meta description: Count downward paths whose sum equals targetSum in O(n) via prefix sum + hash map, with derivation, tradeoffs, and multi-language implementations. Target Readers LeetCode learners who want a reusable “tree + hash map” template People who tend to write O(n²) when the path does not have to start at the root Engineers working with hierarchical data (call traces, org trees) who need “downward segment” statistics Background / Motivation Many “tree path” problems hide a trap: you naturally assume paths start at the root, or end at leaves — but this problem allows the path to start and end at any nodes, as long as the direction is downward (parent → child). ...

February 4, 2026 · 15 min · map[name:Jeanphilo]