Quick actions

cmd+k|ctrl+k

Navigation

Languages

Kth smallest element 

Snippet info

Language

Cpp

Visibility

public

Author

amangoyal1727

Created

2021-01-11T00:30:28Z

Updated

2021-01-11T00:34:24Z

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    
    // priority_queue<int> maxh;
    
    int k;
    cin>>k;
    
    vector<int> A = {7, 10 , 4 ,3 ,20 ,15};
    
    sort(A.begin(), A.end());
    
    cout<<A[k-1]<<endl;
     
    
}

//Above method is by using sorting in STL in O(nlogn)
//We can also do this with the help of heap ds in stl;

INFO