Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Consider changing the numbers that are strictly greater than k in the array to 1, the numbers that are strictly smaller than k to -1, and k to 0.
After the change, what property does a subarray with median k have in the new array?
An array with median k should have a sum equal to either 0 or 1 in the new array and should contain the element k. How do you count such subarrays?