Free written solutionShortest Unsorted Continuous Subarray (LeetCode 581): Solution and Explanation
Find the shortest continuous piece of nums that, once sorted on its own, leaves the whole array sorted, and return its length. For [2,6,4,8,10,9,15] the piece is [6,4,8,10,9], so the answer is 5. A sorted array gives 0.
Read the intuition, approach, code and complexity →