I tried a lot but am not able to code this problem can you plz help me out.
Merge k sorted array
his Min Heap based solution has same time complexity which is O(nk Log k).
- Create an output array of size n*k.
- Create a min heap of size k and insert 1st element in all the arrays into the heap
- Repeat following steps n*k times.
a) Get minimum element from heap (minimum is always at root) and store it in output array.
b) Replace heap root with next element from the array from which the element is extracted. If the array doesn’t have any more elements, then replace root with infinite. After replacing the root, heapify the tree.
if you want help with the coding part i can help directly
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.