#3578

Count Partitions With Max-Min Difference at Most K

specialist · 755 · lc medium +31 · 58.8% accepted · 528 likes · top 55%

Description

Given an integer array nums and an integer k, divide nums into one or more non-empty contiguous parts so that in every part the difference between the largest and smallest values is at most k.

Return the number of valid partitions modulo 109 + 7.

Code

1
2
3