Tap here to switch tabs
Problem
Submissions

Problem: Divide Array Into Arrays With Max Difference

Divide Array Into Arrays With Max Difference asks you to split an array into groups of three where every group's maximum and minimum differ by at most k, or return an empty array when impossible.

Statement

You are given an integer array nums of size n and a positive integer k.

Divide nums into n3\frac{n}{3} arrays, each of size 33, such that the difference between any two elements within the same array is at most k.

Return a 22D array containing all the resulting arrays. If no valid division exists, return an empty array. If multiple valid configurations exist, return any of them.

Constraints:

  • n ==== nums.length

  • 1≤1 \leq n ≤105\leq 10^5

  • n is a multiple of 33

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Divide Array Into Arrays With Max Difference

Divide Array Into Arrays With Max Difference asks you to split an array into groups of three where every group's maximum and minimum differ by at most k, or return an empty array when impossible.

Statement

You are given an integer array nums of size n and a positive integer k.

Divide nums into n3\frac{n}{3} arrays, each of size 33, such that the difference between any two elements within the same array is at most k.

Return a 22D array containing all the resulting arrays. If no valid division exists, return an empty array. If multiple valid configurations exist, return any of them.

Constraints:

  • n ==== nums.length

  • 1≤1 \leq n ≤105\leq 10^5

  • n is a multiple of 33

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤105\leq 10^5