What is wrong in my approach?


#1

int Solution::kthsmallest(const vector &A, int B) {
int count;
for(int i=0;i<A.size();i++)
{count=0;
for(int j=0;j<A.size();j++)
{
if(A[i]>=A[j])count++;
}
if(count==B)return A[i];
}
}

It is working for smaller values of B ,but for the test case: A : [ 60, 94, 63, 3, 86, 40, 93, 36, 56, 48, 17, 10, 23, 43, 77, 1, 1, 93, 79, 4, 10, 47, 1, 99, 91, 53, 99, 18, 52, 61, 84, 10, 13, 52, 3, 9, 78, 16, 7, 62 ]
B:22 ;it is showing runtime error.


#2

your approach is taking O(n^2) time complexity whereas expected time complexity is <=O(nlogn). That why you are getting TLE for higher values of n