Count Subarrays with a Given Sum

Asked at Waymo · Coding Questions · Difficulty: Medium · Last asked May 13, 2026

Given a list of integers (which may be negative) and a target `k`, count how many contiguous subarrays have a sum exactly equal to `k`. Subarrays that occupy different positions are counted separately, even when their elements are equal.

Loading the problem…