5 ms·
Heap sounds like overkill to find the middle value in a running list. What's wrong with simple stack and keeping track of how many integers you've received?
by sixothree 14y ago
Heap sounds like overkill to find the middle value in a running list. What's wrong with simple stack and keeping track of how many integers you've received?
- jbritto 14y agoI'm not sure what you have in mind (perhaps finding the mean? but why the stack?) but that would not work for median.
- xyzzyz 14y agoWhat's wrong with simple stack and keeping track of how many integers you've received? I'm sorry, but I have absolutely no idea what you are talking about. Perhaps you could describe your solution a bit more.
- Drbble 14y agoYour solution is for median position, not median value, and it would require a queue, not a stack, so unneeded old values could be dropped.
- sixothree 14y agoOf course, a queue is correct.