A moving median smooths a sequence by taking the median of every complete sliding window. Sorting a window places its middle value or values at known positions.
For an odd window size, use the single middle value. For an even window size, use the average of the two middle values. Return one floating-point median for each complete window.
Input: values = [1, 3, 5, 7, 9], window_size = 3
Output: [3.0, 5.0, 7.0]
Explanation: The middle values of the three sorted windows are 3, 5, and 7.
Input: values = [1, 2, 3, 4], window_size = 2
Output: [1.5, 2.5, 3.5]
Use sorted on each slice of length window_size.
The middle index is window_size // 2.
Sign in to take notes on this problem
Accepts: array
Accepts: number
A moving median smooths a sequence by taking the median of every complete sliding window. Sorting a window places its middle value or values at known positions.
For an odd window size, use the single middle value. For an even window size, use the average of the two middle values. Return one floating-point median for each complete window.
Input: values = [1, 3, 5, 7, 9], window_size = 3
Output: [3.0, 5.0, 7.0]
Explanation: The middle values of the three sorted windows are 3, 5, and 7.
Input: values = [1, 2, 3, 4], window_size = 2
Output: [1.5, 2.5, 3.5]
Use sorted on each slice of length window_size.
The middle index is window_size // 2.
Sign in to take notes on this problem
Accepts: array
Accepts: number