From f0748056ab5db3b9de1f471a6fc74d1d6f923651 Mon Sep 17 00:00:00 2001 From: Krishnendu <91654756+krishnendu-2021@users.noreply.github.com> Date: Sun, 16 Oct 2022 07:43:14 +0530 Subject: [PATCH] Kth largest element in an array --- Kth_Largest_Element_in_an_Array.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Kth_Largest_Element_in_an_Array.cpp diff --git a/Kth_Largest_Element_in_an_Array.cpp b/Kth_Largest_Element_in_an_Array.cpp new file mode 100644 index 0000000..1636d92 --- /dev/null +++ b/Kth_Largest_Element_in_an_Array.cpp @@ -0,0 +1,15 @@ +public: + int findKthLargest(vector& nums, int k) { + priority_queue pq; + for(auto i : nums){ + pq.push(i); + } + int i = 1; + while(i!=k){ + pq.pop(); + i++; + } + return pq.top(); + + } +};