Tap here to switch tabs
Problem
Submissions

Problem: Shortest Unsorted Continuous Subarray

Shortest Unsorted Continuous Subarray asks you to return the length of the shortest contiguous section that, when sorted, makes the entire integer array nondecreasing, or zero if already sorted.

Statement

Given an integer array nums, return the length of the shortest contiguous subarray such that sorting only that subarray in nondecreasing order makes the entire array nums sorted in nondecreasing order. If nums is already sorted in nondecreasing order, return 00.

Note: Follow up: can you solve it in O(n)O(n) time complexity?

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Unsorted Continuous Subarray

Shortest Unsorted Continuous Subarray asks you to return the length of the shortest contiguous section that, when sorted, makes the entire integer array nondecreasing, or zero if already sorted.

Statement

Given an integer array nums, return the length of the shortest contiguous subarray such that sorting only that subarray in nondecreasing order makes the entire array nums sorted in nondecreasing order. If nums is already sorted in nondecreasing order, return 00.

Note: Follow up: can you solve it in O(n)O(n) time complexity?

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5