Shortest unsorted subarray

Write codeMedium25 min

Your task

Given an integer array a, find the length of the shortest contiguous subarray that, if sorted in place, would make the entire array sorted in ascending order. If the array is already sorted, return 0.

Examples

shortest_unsorted_subarray(a: list[int]) -> int
Example 1
Inputshortest_unsorted_subarray([2, 6, 4, 8, 10, 9, 15])
Output5