You are given an integer array nums and an integer k.
Your goal is to divide the array into one or more continuous non-empty segments such that, for every segment, the difference between the largest and smallest elements is at most k.
Return the total number of possible partitions that satisfy this property.
Because the result could be very large, return the answer modulo (10⁹ + 7).
Input: nums = [2, 5, 4], k = 3
Output: 4
Explanation:
Possible valid partitions: [[2], [5], [4]] [[2,5], [4]] [[2], [5,4]] Each segment’s (max - min) ≤ 3, so total = 3.
Input: nums = [1, 2, 3, 6], k = 2
Output: 4
Explanation:
Valid partitions include: [[1], [2], [3], [6]] [[1,2,3], [6]] [[1,2], [3], [6]] [[1], [2,3], [6]] No other configuration keeps all (max - min) ≤ 2.
Accepted:
Submission: