Shortest subarray whose max minus min is at least K

0
Remix

Given an integer array and k, return the length of the shortest contiguous subarray in which the largest value minus the smallest value is at least k, or -1 if none exists. Aim for linear time.

MetaCodingLast asked Oct 2025
No answer yet. Write the first one; the best answer gets endorsed.