2294. Partition Array Such That Maximum Difference Is K
On This Page
class Solution:
def partitionArray(self, nums: List[int], k: int) -> int:
nums.sort()
res, a = 1, nums[0]
for b in nums:
if b - a > k:
a = b
res += 1
return res