Preview:
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();
        
    }
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter