Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Amelia Sharpe
Is the runtime correct?

Amelia Sharpe

Aug 4, 2023

Why is the runtime O(logN) instead of O(NlogN)? It takes O(logN) to insert an element and balance the two heaps. And if we are inserting N elements, shouldn't the overall runtime be O(NlogN)?

1

0

Comments
Comments
J
Jimmy 2 years ago

It's correct. The runtime for a single call to insertNum() is O(log N), which is what the solution stated. We were asked to implement the insertNum() and findMedian() methods so we should provide the space and time complexity for just those methods. We're not given how ...

On this page