raghuvanshraj

215.cpp

Jul 30th, 2021
650
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  *    author:   vulkan
  3.  *    created:  29.07.2021 06:35:05 PM
  4. **/
  5. #include <bits/stdc++.h>
  6.  
  7. using namespace std;
  8.  
  9. int findKthLargest(vector<int>& nums, int k) {
  10.     priority_queue<int> max_heap(nums.begin(), nums.end());
  11.     k--;
  12.     while (k--) {
  13.         max_heap.pop();
  14.     }
  15.     return max_heap.top();
  16. }
  17.  
  18. int main(int argc, char const *argv[]) {
  19.     int n;
  20.     cin >> n;
  21.     vector<int> nums(n);
  22.     for (int i = 0; i <= n - 1; ++i) {
  23.         cin >> nums[i];
  24.     }
  25.     int k;
  26.     cin >> k;
  27.     cout << findKthLargest(nums, k);
  28.  
  29.     return 0;
  30. }
RAW Paste Data