Code Room
CodingMediumcod-g1293
Subject Prefix sumLevel Entry–Mid~16 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A water tank logs one signed flow value per minute: positive means water in, negative means water out. An auditor wants to know how many contiguous stretches of minutes had a net flow of exactly k liters. Count every such stretch (non-empty, any length, any starting minute). Flows and k may be zero or negative, so stretches can overlap and shorter stretches inside longer ones count separately. Example: flows = [2, -2, 2, -2], k = 0 gives 4.

Implement
count_net_stretches(flows: list[int], k: int) → int
Examples
in[[2,-2,2,-2],0]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.