Skip to content

Commit bb06dc0

Browse files
committed
Jun 19
1 parent 9ea5bdc commit bb06dc0

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def partitionArray(self, nums: list[int], k: int) -> int:
3+
nums.sort()
4+
curr_min = nums[0]
5+
count = 1
6+
for num in nums[1:]:
7+
if num - curr_min > k:
8+
count += 1
9+
curr_min = num
10+
return count
11+
12+
13+
def main():
14+
nums = [3, 6, 1, 2, 5]
15+
k = 2
16+
assert Solution().partitionArray(nums, k) == 2
17+
18+
nums = [1, 2, 3]
19+
k = 1
20+
assert Solution().partitionArray(nums, k) == 2
21+
22+
nums = [2, 2, 4, 5]
23+
k = 0
24+
assert Solution().partitionArray(nums, k) == 3
25+
26+
27+
if __name__ == '__main__':
28+
main()

2025-06-June-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
| June 16 | [2016. Maximum Difference Between Increasing Elements](https://leetcode.com/problems/maximum-difference-between-increasing-elements/) | Easy | Solved |
2323
| June 17 | [3405. Count the Number of Arrays with K Matching Adjacent Elements](https://leetcode.com/problems/count-the-number-of-arrays-with-k-matching-adjacent-elements/) | Hard | Unsolved |
2424
| June 18 | [2966. Divide Array Into Arrays With Max Difference](https://leetcode.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | Solved |
25-
| June 19 | []() | | |
25+
| June 19 | [2294. Partition Array Such That Maximum Difference Is K](https://leetcode.com/problems/partition-array-such-that-maximum-difference-is-k/) | Medium | Solved |
2626
| June 20 | []() | | |
2727
| June 21 | []() | | |
2828
| June 22 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 3 | 3 | 0 |
43-
| Medium | 8 | 5 | 3 |
43+
| Medium | 9 | 6 | 3 |
4444
| Hard | 5 | 2 | 3 |

0 commit comments

Comments
 (0)