Tap here to switch tabs
Problem
Submissions

Problem: Smallest Subarray to Sort in Every Sliding Window

med
30 min
Try to solve the Smallest Subarray to Sort in Every Sliding Window problem.

Statement

You are given an integer array nums and an integer k.

Consider every sliding window of size k moving from left to right across nums. For each window, find the length of the shortest continuous subarray that, if sorted in ascending order, makes the entire window sorted in ascending order. If a window is already sorted, the length is 00.

Return an array of integers where each element corresponds to the minimum subarray length required to sort that respective window.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq k ≤\leq nums.length

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Smallest Subarray to Sort in Every Sliding Window

med
30 min
Try to solve the Smallest Subarray to Sort in Every Sliding Window problem.

Statement

You are given an integer array nums and an integer k.

Consider every sliding window of size k moving from left to right across nums. For each window, find the length of the shortest continuous subarray that, if sorted in ascending order, makes the entire window sorted in ascending order. If a window is already sorted, the length is 00.

Return an array of integers where each element corresponds to the minimum subarray length required to sort that respective window.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 1≤1 \leq k ≤\leq nums.length

  • 1≤1 \leq nums[i] ≤106\leq 10^6