Write count_subarrays(nums: list[int], target: int) -> int.
All values in nums are positive. Count the contiguous, non-empty subarrays whose elements add up to exactly target.
Example: nums = [1, 3, 2, 1, 4, 1], target = 5 gives 3: [3, 2], [1, 4] and [4, 1].
nums = [2, 2, 2], target = 2 gives 3.
Constraints: 1 <= len(nums) <= 2 * 10^5, 1 <= nums[i], target <= 10^9.
Checking every start/end pair is O(n²) and fails the large test. Aim for O(n).
Show hint
because every value is positive, extending a subarray on the right only increases its sum and dropping elements on the left only decreases it. Can both ends move forward only?