Count how many contiguous subarrays of length three satisfy a given condition.
You are given an integer array nums. Consider every contiguous subarray of length 3.
Count how many of these length-3 subarrays satisfy the required condition from the problem statement. Return the count.
The exact condition is simple and local to each triplet, so the intended solution is to scan the array once and evaluate each window of size three.
nums.nums contains at least 3 elements for valid windows to exist.3 <= nums.lengthExample 1
Input
nums = [1, 2, 3, 4, 5]
Output
3
Explanation
The length-3 windows are [1,2,3], [2,3,4], and [3,4,5]. For this illustrative version, each window satisfies the local condition, so the count is 3.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.