bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold

1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold

Leetcode Solutions

Sliding Window Approach

  1. Initialize a variable count to store the number of valid subarrays.
  2. Calculate the initial sum of the first k elements.
  3. Iterate over the array starting from the k-th element.
    • For each iteration, check if the current sum divided by k is greater than or equal to threshold.
    • If it is, increment count.
    • Update the sum by subtracting the element that is leaving the window and adding the element that is entering the window.
  4. Return the value of count.
UML Thumbnail

Cumulative Sum Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...