
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can we use dynamic programming here?
To minimize the answer, the array should be sorted first.
The recurrence relation is fn(i, x) = min(fn(i+1, x), max(abs(nums[i]-nums[i+1]), fn(i+2, p-1)), and fn(0,p) gives the desired answer.