Dsa
Heap
Hard
Median Sliding Window
You are given an array of integers and a window size K. Write a function to return the median of each sliding window of size K in the array.
Input Format:
- The first line contains two integers N (number of elements) and K (window size).
- The second line contains N integers separated by spaces.
Output Format:
- Print the medians for each sliding window separated by spaces, rounded to one decimal place.
Example Input:
8 3
1 3 -1 -3 5 3 6 7
Example Output:
1.0 -1.0 -1.0 3.0 5.0
Key concepts
heapsliding_windowmedian
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now