1
class Solution:
2
def partitionArray(self, nums: List[int], k: int) -> int:
3
nums.sort()
4
ans = 1
5
# To keep track of starting element of each subsequence
6
start = nums[0]
7

8
for i in range(1, len(nums)):
9
diff = nums[i] - start
10
if diff > k:
11
# If difference of starting and current element of subsequence is greater
12
# than K, then only start new subsequence
13
ans += 1
14
start = nums[i]
15

16
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0