Moving Median
Given an array of integers, return the moving median for each element based on the element and its N-1 predecessors, where N is the sliding window size.
The final output should be a string with the moving median corresponding to each entry in the original array, separated by commas.
Note that for the first few elements, until the window size is reached, the median is computed on a smaller number of entries.
For example: if arr = [3, 1, 3, 5, 10, 6, 4, 3, 1], then your program should output 3,2,3,3,3,5,5,4,4.
Examples
[5, 2, 4, 6]→2,3,4[3, 0, 0, -2, 0, 2, 0, -2]→0,0,0,0,0,0,0
This problem asks for the median of a sliding window ending at each position, using fewer elements at the beginning until the full window size is reached. The output must preserve the original order and join each median with commas. A straightforward solution is to sort each window and pick the middle value, while more advanced implementations can use two heaps or another ordered data structure for better performance.