Budget Window Score Audit
Preview mode. Log in to edit, run, submit, and save progress.
Budget Window Score Audit
A finance gateway receives a stream of positive integer costs. For any contiguous subarray, the gateway defines its audit score as the sum of the subarray multiplied by the length of the subarray. You must count how many contiguous subarrays have audit score strictly less than k. The subarray must keep the original order and cannot skip elements. Input Format: You are given an integer array nums and a positive integer k. Output Format: Return the number of contiguous subarrays whose audit score is less than k.
Examples
nums = [2, 1, 4, 3, 5] k = 18
9
Explanation: 5 window(s) of length 1, 4 window(s) of length 2 has sum * length below 18. Total valid windows = 9.
Approach hint
Keep one expandable window.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.