i am struck in the implementation of this in half way help
,also i am not able understand the time complexity told in the video help, for brute force and optimized one
question–>
https://practice.geeksforgeeks.org/problems/kth-element-in-matrix/1
code–>
implementing brute force (struck in half way)
Kth smallest element is col row sorted 2d array
BruteForce Approach
int kthSmallest(int mat[MAX][MAX], int n, int k)
{
int new_mat[100000];
int x=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
new_mat[x++]=mat[i][j];
}
}
int size=x;
sort(new_mat,new_mat+size);
return new_mat[k-1];
}
Optimised Approach
i think now time complexity of both the approach is clear
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.