Please give me the optimised code of this que.
$ Kth Smallest Element In Row And Col Wise Sorted Array Hint
first try at your own
Approach: So the idea is to find the kth minimum element. Each row and each column is sorted. So it can be thought as C sorted lists and the lists have to be merged into a single list, the kth element of the list has to be found out. So the approach is similar, the only difference is when the kth element is found the loop ends.
Algorithm:
- The idea is to 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 tried but getting wrong ans
So please send me a code…
we can’t directly send you the code
if you have tried send me the link of code
i will tell you errors and provide modified code
I am stucked at this point…please help me
I have sent my code…I am stucked.I dont want to leave this que . Just modify my code and send me.
sorry for late reply
the way in which you have taken the vector of vector is wrong
see the correct way
also i have done some modifications
please watch hint video first i have use the same logic
Modified Code
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.