mediumArraysPattern: Subarray

Min Length Subarray with Bounded Average Solution

Problem Statement

You are given an array of integers `values` and a target average `threshold`. Determine the minimum length of a contiguous subarray such that the average of the elements in this subarray is less than or equal to `threshold`. If no such subarray exists, return `-1`.

Constraints

  • A is an array of integers.
  • avg is a number.
  • The length of A is between 1 and 10^6.
  • The elements of A are between -10^6 and 10^6.
Time: O(n) Space: O(n)
Analyze constraints and compute optimal solutions step-by-step.

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.