Question bank › Prefix Sum
Dsa Prefix Sum Medium

Balanced Water Balances

You are tracking water levels in a reservoir for a number of days. Each day, a positive integer indicates water added, while a negative integer indicates water drained. Given an integer N for the number of days and an integer T for a target water level, determine how many days have a water level that is exactly T using prefix sums. Input: - The first line contains two integers N (1 ≤ N ≤ 100,000) and T (−1,000,000 ≤ T ≤ 1,000,000). - The second line contains N integers representing daily changes in water levels (−1000 ≤ daily_change ≤ 1000). Output: - Output a single integer, the number of days where the water level equals T. Example: Input: 5 4 1 -1 3 1 0 Output: 2

Key concepts

prefix_sumarray

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.