Back to problems

Subarray Score ≤ K (Sliding-Window)

Algorithm · Pinterest · Medium

Requirements You receive an integer array arr together with an integer K. Determine how many contiguous ranges arr[i..j] satisfy the condition Your algorithm should run in O(n) time. Examples Notes When every element is non-negative, extending the right boundary cannot decrease sum * length. This permits a sliding-window approach: track (left, right) along with the current sum, and move left forward whenever the window score is above K. Afterward, the number of valid ranges…

Checking your access…