:orphan: Kth Largest Element in an Array =============================== .. highlight:: none Problem ------- https://leetcode.com/problems/kth-largest-element-in-an-array/ Given an integer array ``nums`` and an integer ``k``, return *the* ``k``\ :sup:`th` *largest element in the array*. Note that it is the ``k``\ :sup:`th` largest element in the sorted order, not the ``k``\ :sup:`th` distinct element. Can you solve it without sorting? **Example 1:** :: Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 **Example 2:** :: Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4 **Constraints:** - ``1 <= k <= nums.length <= 10``\ :sup:`5` - ``-10``\ :sup:`4`\ ``<= nums[i] <= 10``\ :sup:`4` .. highlight:: python Pattern ------- Heap, Sorting Approaches ---------- .. tab-set:: .. tab-item:: Min Heap **Code** .. literalinclude:: ../problems/medium/kth-largest-element-in-an-array/kth_largest_element_in_an_array__min_heap.py :language: python :lines: 9- **Test** >>> from kth_largest_element_in_an_array__min_heap import findKthLargest >>> findKthLargest([3, 2, 1, 5, 6, 4], 2) 5 >>> findKthLargest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) 4 .. autofunction:: kth_largest_element_in_an_array__min_heap.findKthLargest