Practice Count Partitions With Max-Min Difference at Most K
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Count Partitions With Max-Min Difference at Most K
Problem Statement
You are given an integer array nums and an integer k. Your task is to partition nums into one or more non-empty contiguous segments such that in each segment, the difference between its maximum and minimum elements is at most k. Return the total number of ways to partition nums under this condition. Since the answer may be too large, return it modulo 10^9 + 7.
Source: Count Partitions With Max-Min Difference at Most K on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [9,4,1,3,7], k = 4
6
# Example 2
nums = [3,3,4], k = 0
2
Constraints
Related LeetCode Problems
Practice more problems similar to Count Partitions With Max-Min Difference at Most K.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.