 All Problems
Shortest Unsorted Continuous Subarray
medium
arrays
sorting
two pointers
amazon
google
microsoft
facebook

Given an integer array nums, find the shortest subarray that, if sorted, makes the whole array sorted. Return its length.

Example 1:

Input: 2 6 4 8 10 9 15
Output: 5

Example 2:

Input: 1 2 3 4
Output: 0

Input format: Space-separated integers.

Output format: Length of the shortest unsorted subarray.

Run to check your code against the sample cases, or submit to run every case