Skip to content
Onsite

X Subarray

EasyP3Coding

Given an array nums of positive integers and two integers x and k, count the contiguous subarrays of length exactly x in which no element is greater than k.

Subarrays are counted by position, so equal subarrays at different positions count separately.

Example 1

Input
nums = [2,1,3,4,1], x = 2, k = 3
Output
2

Example 2

Input
nums = [1,2,3], x = 1, k = 2
Output
2

Example 3

Input
nums = [5,5,5], x = 2, k = 4
Output
0

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= x <= nums.length
  • 1 <= nums[i], k <= 10^9

Hints

Run checks the 3 visible tests, Submit all 11.