Find kth largest

what is wrong in my code?

WHat happened…why the doubt section is not responding on time
it’s been 3 days

hi @abhinavssr2003_eab0717682969e5c print directly when u got the index

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	int k;
	cin>>n>>k;
	int a[1000000];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	k=n-k;
	cout<<a[k]<<endl; // like this 
	return 0;
}


sorry for late reply, i was not well.
hope this helps :slight_smile:

It’s ok but is not there any other who is taking the doubts??And what is wrong in my one…Actually earlier i tried with the approach you send now but it was not working

It is showing wrong output

Is the code i shared working ? @abhinavssr2003_eab0717682969e5c

NO it is not working

@abhinavssr2003_eab0717682969e5c working for me please check

hi @abhinavssr2003_eab0717682969e5c should work let me talk with team

When I am printing the sorted array…it is then also printing wrong i don’t know why

Well i got the mistake…IN your code too you are taking input of k just after takin the input of n…so basically you are taking the first element of array as input k…so k should get input after inputting the array