Quant Memo
Coding/●●●●

Shortest window that sorts the whole array

Given an array, find the length of the shortest contiguous subarray such that sorting just that subarray makes the whole array sorted ascending. If the array is already sorted, the answer is 0.

nums = [2, 6, 4, 8, 10, 9, 15]  ->  5     # sort indices 1..5

Return the length of that shortest window. Aim for O(n)O(n) time and O(1)O(1) space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions