Tap here to switch tabs
Problem
Submissions

Problem: Partition Array Such That Maximum Difference Is K

med
30 min
Try to solve the Partition Array Such That Maximum Difference Is K problem.

Statement

Given an integer array nums and an integer k, partition nums into the minimum number of subsequences such that each element in nums belongs to exactly one subsequence.

Return the minimum number of subsequences required such that the difference between the maximum value and the minimum value in every subsequence is at most k.

Note: A subsequence is a sequence that can be derived from an array by deleting zero or more elements without changing the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

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

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Partition Array Such That Maximum Difference Is K

med
30 min
Try to solve the Partition Array Such That Maximum Difference Is K problem.

Statement

Given an integer array nums and an integer k, partition nums into the minimum number of subsequences such that each element in nums belongs to exactly one subsequence.

Return the minimum number of subsequences required such that the difference between the maximum value and the minimum value in every subsequence is at most k.

Note: A subsequence is a sequence that can be derived from an array by deleting zero or more elements without changing the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

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

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