Meta Interview Question

Data structure for numbers that supports 2 operations: insert and get_median.

Interview Answers

Anonymous

Jun 15, 2012

Keep track of median. Use min heap and max heap. During insertion if number is greater than median, insert into the min heap. If the number is less than the median, insert into the max heap. Delete/insert/replace median if heap size differs by more than 1. Or use a mmm-heap (min-max-median heap).

4

Anonymous

Jun 3, 2012

Use min heap and a max heap.

Anonymous

Jun 7, 2012

BST already supports those.