← Questions

Count subarrays that sum to K

0
AppleCodingLast asked Feb 2026

Given an array of integers (negatives allowed) and k, count the contiguous subarrays whose sum is exactly k. Keep running prefix sums and a map from each prefix sum to how often it has appeared.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding