Google Onsite - London
Anonymous User
2523

I recently did an interview for google (L4) and I failed in one of the rounds. The question was:

Supposing that you have a stream of integer, implement the following two methods to return the median value (value of the middle. It's not the mean). The median value does not need to be exact. It can be within a range of 2^n-1 to 2^n+1.
For example:
addValue(1)
addValue(6)
addValue(10)
getMedian() can return any value between 4 to 7.

Hint: After some time I was using 2 priority queues to calculate the median. However, the interviewer highlighted that he don't need the exact median, but any of the values within the range, as can be seen in the above example.
Hint 2: the solution seems to be to have an array with 64 buckets and every time a value is added, this array will increment 1 on the bucket where the value belongs to. To be honest I didn't understand the question completely and that's one of the reasons I didn't have time enough to implement, thus I failed.

Comments (10)