You decide to test if your oddly-mathematical heating company is fulfilling its All-Time Max, Min, Mean and Mode Temperature Guarantee™.
Write a class TempTracker with these methods:
insert—records a new temperature
getMax—returns the highest temp we've seen so far
getMin—returns the lowest temp we've seen so far
getMean—returns the mean of all temps we've seen so far
getMode—returns a mode of all temps we've seen so far
Optimize for space and time. Favor speeding up the getter functions (getMax, getMin, getMean, and getMode) over speeding up the insert function.
getMean should return a double, but the rest of the getter functions can return integers.
Temperatures will all be inserted as integers. We'll record our temperatures in Fahrenheit, so we can assume they'll all be in the range 0..110.
If there is more than one mode, return any of the modes.
We can get time for all functions.
We can get away with only using additional space. If you're storing each temperature as it comes in, be careful! You might be taking up space, where n is the number of temperatures we insert!
Are you trying to be fancy about returning multiple modes if there's a tie? Good idea, but read the problem statement carefully! Check out that last sentence!
Failing to carefully read or listen to the problem statement is a very common mistake, and it always looks bad. Don't let it happen to you.