this is the code i tried to find kth largest element.
I sorted array in descending order and printed element at (k-1) position .
But i am not getting correct output for sort function for this input:
6
2
3 2 1 5 6 4
this is the code i tried to find kth largest element.
I sorted array in descending order and printed element at (k-1) position .
But i am not getting correct output for sort function for this input:
6
2
3 2 1 5 6 4
hello @srividhya_14 i would like to help you in the better way for that i request you to please share the question with me .
@srividhya_14 the code for this is very simple .
i am exaplaining the logic to do :
suppose the array is unsorted then just sort the array and make k as k=n-k
and then take one counter variable which will keep on incrementing and if at any point it becomes equal to k then you have to output that number then .
Happy Learning !!
I tried but i am not getting the output .
try now.
Happy Learning !!
ya it worked . Thank you.
May i know what changes you made??
in line 7 cin>>n>>k; this is correct and you were doing wrong in this line .
if you feel that your doubt is cleared please mark this doubt as resolved.
Happy Learning !!