Ski Resort

You are given an integer array nums representing the daily temperature forecast at a resort. You are also given two integers k and q.

You want to plan a vacation by choosing a contiguous subarray of days from nums. The vacation must satisfy two conditions:

  • The vacation must last for at least k consecutive days.
  • The temperature on every single day of the vacation must be less than or equal to q.

Calculate and return the total number of different ways you can choose valid vacation dates.

Example 1:

Input: nums = [-5, 0, -10], k = 1, q = 15

Output: 6

Explanation:

All 3 days have temperatures <= 15. Since k = 1, any contiguous subarray is valid: [-5], [0], [-10], [-5, 0], [0, -10], and [-5, 0, -10]. Total = 6.

Example 2:

Input: nums = [12, 12, 10, 15], k = 3, q = 12

Output: 1

Explanation:

The only contiguous subarray of length >= 3 where all elements are <= 12 is the first three days: [12, 12, 10]. The temperature 15 on the last day ruins any subarray that includes it.

Now Your Turn!

Pick the correct output for the given input

Input: nums = [0, 3, -2, 5, -4, -4], k = 1, q = 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 2 * 105
  • 1 <= k <= nums.length
  • -109 <= q <= 109
  • -109 <= nums[i] <= 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
long long countValidVacations(vector<int>& nums, int k, int q) {
}
};
Test Case

Input:

K
Nums
Q