⌘K
Flycodx

Water Pressure Flow Optimization

Water Pressure Flow Optimization

HardArrays100% accepted

Mumbai's water department manages pressure levels across M districts using N pump stations. The pressure array must be transformed such that every K-length subarray has balanced pressure (mean = median). Find the minimum adjustments needed.

Approach

Return the number of contiguous windows of length K whose arithmetic mean equals their median. solve(N, K, pressure).

Input

N=5, K=3, pressure=[2,4,6,8,10]

Output

3
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3