← Questions

Shortest subarray whose max minus min is at least K

0
MetaCodingLast asked Oct 2025

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.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding