Dsa
Heap
Medium
Median of Sliding Window
Given an integer array nums and a sliding window size k, calculate the median of each sliding window. The median is the number which separates the higher half from the lower half of the data.
Input Format:
- The first line contains integers N and K (1 <= N <= 10^5, 1 <= K <= N).
- The second line contains N integers (1 <= nums[i] <= 10^5) representing the array.
Output Format:
- Output a single line containing the medians of each sliding window, rounded to 2 decimal places, separated by space.
Example:
Input:
5 3
1 3 -1 -3 5 3 6 7
Output:
1.00 -1.00 -1.00 3.00 5.00
Key concepts
heapmediansliding window
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