Shortest Unsorted Continuous Subarray

Medium · Arrays & Strings · about 20 minutes

Asked at Google, Amazon, Microsoft, ByteDance, eBay.

Find the shortest contiguous subarray that, if sorted ascending, makes the whole array sorted. Return its length (0 if the array is already sorted).

Related guides