Tap here to switch tabs
Problem
Submissions

Problem: Divide Array Into Arrays With Max Difference

med
30 min
Try to solve the Divide Array Into Arrays With Max Difference problem.

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

med
30 min
Try to solve the Divide Array Into Arrays With Max Difference problem.

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