Implementation of kth smallest element

how to implement this code and reduce the space complexity of the particular alogorith

@aslesha.j7 hey ek tareeka to ye hai ki pure 2 d matrix ko 1 d array me copy krlo and sort it and find kth smallest but that will take extra space ,so try this:
Use min heap. Create a Min-Heap to store the elements
Traverse the first row from start to end and build a min heap of elements from first row. A heap entry also stores row number and column number.
Now Run a loop k times to extract min element from heap in each iteration
Get minimum element (or root) from Min-Heap.
Find row number and column number of the minimum element.
Replace root with the next element from same column and min-heapify the root.
Print the last extracted element, which is the kth minimum element

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.