Python data engineering interview problem. Difficulty: intermediate. Pattern: Hashing. About 14 minutes. Part of the Pro drill bank.
Count subarrays whose sum equals k. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement subarray_sum(nums: list, k: int) -> int.
Input: subarray_sum([1, 1, 1], 2) Output: 2 Two windows of sum 2.
Topics: lakebench, python, prefix sum, hash map.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Count subarrays whose sum equals k.
Implement `subarray_sum(nums: list, k: int) -> int`. Example: `[1, 1, 1], 2` → `2`. Keep the harness.