educative.io

Educative

Why not O(m*logm + k * logm) time?

Before we start popping off k elements from the min heap, doesn’t it also require O(m * logm) to build the initial min heap?

2 Likes

Yeah. It requires time complexity of O(m*logm). And if we add these two values then it becomes nearly equal to O(2klogm). Here we can ignore constant and then it becomes O(klogm).