#2966
Divide Array Into Arrays With Max Difference
pupil · 465 · lc medium +26 · 79% accepted · 1,165 likes · top 90%
Description
You are given an integer array nums whose length n is a multiple of 3, and a positive integer k. Split nums into n / 3 groups of three elements each so that every group's max minus min is at most k.
Return a 2D array of the groups, or an empty array if no valid split exists.
Code
1
2
3