Median in a stream of integers

its giving tle for two test cases

hello @gulatigarvita08
check now ->

But why are we making it long??

u can use int as well it will work fine.

we are typecasting it to int/long becuase in question it is mentioned to print only integer part (i,e if answer is 2.5 then print only 2) and typecasting is doing same thing.

but median is already of type int … and when we are doing ( (max.top()+min.top())/2 ) it would give int only…

yeah but the difference lies on the way we store and retrieve them.
int/long we store them direclty in binary

but in case of floats or double we store three information
a) sign b) exponent c) significant bits and while retrieving we need to consider these these information to get our original number.may be this conversion is making ur program slow

can you please explain it in detail…

i have already explained u the reason.
if u have doubt regarding how float are stored then pls refer this->link

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.