educative.io

Runtime Complexity

Isn’t the runtime of the constructor O(N * logN) and wouldn’t this be our concern? Or is it because we are only running the ‘add’ function in the test cases that we concern ourselves with it’s runtime?

I believe the time complexity of constructor would be O(N*logK). logK for doing an add and call add N times for all the numbers in the constructor.

3 Likes

Yes, that’s correct


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Kth Largest Number in a Stream (medium) - Grokking the Coding Interview: Patterns for Coding Questions