Dsa
Arrays
Hard
Median of Subarrays
Given an array and a number K, find the median of every subarray of length K. If the size of the subarray is odd, the median is the middle element; if even, it is the average of the two middle elements.
Input:
The first line contains an integer N, the size of the array.
The second line contains N space-separated integers.
The third line contains the integer K.
Output:
Output a single line containing space-separated medians of each subarray of length K.
Example:
Input:
6
1 3 5 7 9 2
3
Output:
3 5 7 7
Key concepts
arrayssortingmedian
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