Proficient Level
Implement the findMedianFromDataStreamFloor method that returns the floor of the median from a stream of values.
The input array nums contains size integer values received from a data stream.
Your task is to return the floor median value. After sorting the values, the floor median is the middle value for odd size and the lower middle value for even size.
For example, for [1,2,3,4], the two middle values are 2 and 3, so the floor median is 2.
A simple way is to sort the received values and directly read the required middle index.
For odd size, (size - 1) / 2 gives the normal middle index. For even size, it gives the lower of the two middle indexes, which matches the floor median requirement.
If the stream has no values, return -1.
Pseudocode:
function findMedianFromDataStreamFloor(nums, size):
if size == 0:
return -1
sort nums in ascending order
index = (size - 1) / 2
return nums[index]