values and an integer spread. Distribute all the numbers into groups: each number goes into exactly one group, and order within a group does not matter.
A group is tight if its largest number minus its smallest number is at most spread.
Return the smallest number of groups such that every group is tight.values=[9, 1, 4, 10, 3], spread=3 → 2
Groups {1, 3, 4} and {9, 10}: in each, the largest minus the smallest is at most 3. One group is not enough, since 10 − 1 = 9.
values=[7, 7, 8], spread=0 → 2
With a spread of 0 a group may only hold equal numbers: {7, 7} and {8}.
values=[5], spread=2 → 1
values=[9, 1, 4, 10, 3], spread=3
2
Run checks the first 3 tests in your browser. Submit checks all 113 tests on the server, hidden ones included.