Kth smallest number

PHOTO EMBED

Sun Jul 31 2022 12:15:43 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution{
    public:
    // arr : given array
    // l : starting index of the array i.e 0
    // r : ending index of the array i.e size-1
    // k : find kth smallest element and return using this function
    int kthSmallest(int arr[], int l, int r, int k) {
       priority_queue<int>maxpq;
       for(int i=l;i<=r;i++)
       {
           maxpq.push(arr[i]);
           if(maxpq.size()>k)
           {
              maxpq.pop();
           }
           
       }
       return maxpq.top();
        
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/kth-smallest-element5635/0