3 ms·
O(1) implies it should always be sorted. So just accessing the top should be the solution. This implies that inserts and removals will be the more complex task.
by drooby 5y ago
O(1) implies it should always be sorted. So just accessing the top should be the solution. This implies that inserts and removals will be the more complex task. The naive approach would just be adding and then sorting - O(nlogn). But the best solution I believe is a max heap.. they essentially wanted you to write a max heap algo.
- melony 5y agoA correct max heap is very difficult to implement from scratch during an interview. Also, shouldn't it be a min-heap?