Problem 2294 · Medium

Partition Array Such That Maximum Difference Is K

Sort the values, then start a new group whenever a value strays more than k above the group start.

Open the interactive visualisation