← 返回 amazon 的题目列表Minimum Groups with Max Difference Constraint
类型:online_judge
Given an integer array, partition the array into the minimum number of groups such that the difference between any two elements in any group is no more than a given integer maxdiff.
For example, given the array [3, 6, 1, 9] and maxdiff = 3, it should return 2 because the array can be partitioned into groups [1, 3] and [6, 9].
Example:
Input: [3, 6, 1, 9], maxdiff = 3
Output: 2
Input: [1, 2, 3, 4, 5], maxdiff = 0
Output: 5
Example
Input
[3, 6, 1, 9], maxdiff=3
Output
2