I don't think time complexity is correct here. The loop is O(N), and inside the loop, and for each node, it requires one heappush and at most one heapop, which is O(2logK), and the total time complexity is O(N*logK). H in time complexity is redundant, one counter example if the tree is skewed, and the time compexity is O(n^2*logk), which could not be true.
I don't think time complexity is correct here. The loop is O(N), and inside the loop, and for each node, it requires one heappush and at most one heapop, which is O(2logK), and the total time complexity is O(N*logK). H in time complexity is redundant, one counter example if the tree is skewed, and the time compexity is O(n^2*logk), which could not be true.
instead of heap O(NlgN), quicksort would serve better O(lgN)
Can you solve #2663 ?