Sliding Window Median
Given an array nums and an integer k, return an array of the median of each window of size k moving from left to right.

30:00

Sliding Window Median
hard
Topics
Companies

Given an array nums and an integer k, return an array of the median of each window of size k moving from left to right.

Example 1:
Input: {"nums":[1,3,-1,-3,5,3,6,7],"k":3}
Output: [1,-1,-1,3,5,6]
Constraints:
  • 1knums.length1051 \leq k \leq \text{nums.length} \leq 10^5

  • 231nums[i]2311-2^{31} \leq \text{nums}[i] \leq 2^{31} - 1

Input
arr ={"nums":[1,3,-1,-3,5,3,6,7],"k":3}

nums: [1, 3, -1, -3, 5, 3, 6, 7], k=3

Array with Sliding Window (k=3)

1

0

3

1

-1

2

-3

3

5

4

3

5

6

6

7

7

Window:

[0, 2]

Result:

[]

Variables
No variables to display
DepthFunction Call
Stack empty
0/1