AlgoMaster Logo

Partition Array Such That Maximum Difference Is K

nums=[3, 6, 1, 2, 5],k=2
0 / 11
algomaster.io
Step:Sort, then try every grouping. Keep each group's max − min ≤ 2.