Back to course home
0% completed
Solution: Divide Array Into Arrays With Max Difference
Problem Statement
You are given an array nums
containing n
integers and a positive integer k
.
Divide the nums
into arrays of size 3
such that it satisfies the below conditions:
- Each element of
nums
should be inexactly
one array. - The
difference
between anytwo elements
of a single array should be less than or equal to k.
Return a 2D array
of these subarrays. If no such division is possible, return an empty
array.
Examples
Example 1:
- Input:
nums = [2, 6, 4, 9, 3, 7, 3, 4, 1]
,k = 3
- Expected Output:
[[1,2,3],[3,4,4],[6,7,9]]
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible