Skip to content

Commit 9ea5bdc

Browse files
committed
Jun 18
1 parent c989493 commit 9ea5bdc

File tree

2 files changed

+25
-2
lines changed

2 files changed

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
| June 15 | []() | | |
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 |
24-
| June 18 | []() | | |
24+
| June 18 | [2966. Divide Array Into Arrays With Max Difference](https://leetcode.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | Solved |
2525
| June 19 | []() | | |
2626
| June 20 | []() | | |
2727
| June 21 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 3 | 3 | 0 |
43-
| Medium | 7 | 4 | 3 |
43+
| Medium | 8 | 5 | 3 |
4444
| Hard | 5 | 2 | 3 |

0 commit comments

Comments
 (0)