Problem Challenge 3

Minimum Window Sort (medium) #

Given an array, find the length of the smallest subarray in it which when sorted will sort the whole array.

Example 1:

Input: [1, 2, 5, 3, 7, 10, 9, 12]
Output: 5
Explanation: We need to sort only the subarray [5, 3, 7, 10, 9] to make the whole array sorted

Example 2:

Input: [1, 3, 2, 0, -1, 7, 10]
Output: 5
Explanation: We need to sort only the subarray [1, 3, 2, 0, -1] to make the whole array sorted

Example 3:

Input: [1, 2, 3]
Output: 0
Explanation: The array is already sorted

Example 4:

Input: [3, 2, 1]
Output: 3
Explanation: The whole array needs to be sorted.

Try it yourself #

Try solving this question here:

0 of 4 Tests Passed
ResultInputExpected OutputActual OutputReason
sort([1, 2, 5, 3, 7, 10, 9, 12])5-1Incorrect Output
sort([1, 3, 2, 0, -1, 7, 10])5-1Incorrect Output
sort([1, 2, 3])0-1Incorrect Output
sort([3, 2, 1])3-1Incorrect Output
5.098s
Mark as Completed
←    Back
Solution Review: Problem Challenge 2
Next    →
Solution Review: Problem Challenge 3