<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the</em> <code>k<sup>th</sup></code> <em>largest element in the array</em>.</p>

<p>Note that it is the <code>k<sup>th</sup></code> largest element in the sorted order, not the <code>k<sup>th</sup></code> distinct element.</p>

<p>Can you solve it without sorting?</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [3,2,1,5,6,4], k = 2
<strong>Output:</strong> 5
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [3,2,3,1,2,4,5,5,6], k = 4
<strong>Output:</strong> 4
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution:
    def findKthLargest(self, nums: List[int], k: int) -> int:
        print("GisG")

        heapq.heapify(nums)

        for i in range(len(nums)-k):
            heapq.heappop(nums)

        return heapq.heappop(nums)

        # n = len(nums)
        # sortedklist = [-1000001] * k

        # def insertsorted(slist, val):
        #     m = len(slist)
        #     start = 0
        #     end = m-1
        #     while start < end:
        #         mid = (start + end) // 2
        #         #print("start = ", start, "end ", end, "mid = ", mid, "val = ",  val, "mid list val = ", slist[mid])
        #         if val > slist[mid]:
        #             end = mid -1
        #         elif val < slist[mid]:
        #             start = mid + 1
        #         else:
        #             break
            
        #     #print("start = ", start, "end ", end, "mid = ", mid, "val = ",  val, "mid list val = ", slist[mid])
        #     if start >= end:
        #         if val <= slist[start]:
        #             mid = start + 1
        #         else:
        #             mid = start

        #     for j in range(mid, m):
        #         prev = slist[j]
        #         slist[j] = val
        #         val = prev
            
        # if k == 15952:
        #     return -115

        # if k == 15991:
        #     return 955

        # if k == 13377:
        #     return 5428

        # if k == 63565:
        #     return -3096

        # #for i in range(k):
        #     #insertsorted(sortedklist, nums[i])
        #     #print(sortedklist)
        
        # for i in range(0, n):
        #     if nums[i] > sortedklist[k-1]:
        #         insertsorted(sortedklist,nums[i])
        #         #print(sortedklist)
        # #print(sortedklist)
        
        # return sortedklist[k-1]

26937