{"pageProps":{"post":{"title":"215. Kth Largest Element in an Array","excerpt":"Given an integer array nums and an integer k, return the kth largest element in the array.\nNote that it is the kth largest element in the sorted order, not the kth distinct element.","featuredImage":{"url":"https://media.graphassets.com/osdqSQYqRsuoPm7N7jhn"},"author":{"name":"Md Jawad Noor Asif","bio":"A humble student of knowledge","photo":{"url":"https://media.graphassets.com/nky5NwkETTKtpNnikulF"}},"createdAt":"2022-06-22T02:50:09.859207+00:00","slug":"kth-largest-element-in-an-array","content":{"raw":{"children":[{"type":"heading-one","children":[{"text":"Problem:"}]},{"type":"paragraph","children":[{"text":"Given an integer array "},{"code":true,"text":"nums"},{"text":" and an integer "},{"code":true,"text":"k"},{"text":", return "},{"text":"the","italic":true},{"text":" "},{"code":true,"text":"kth"},{"text":" "},{"text":"largest element in the array","italic":true},{"text":"."}]},{"type":"paragraph","children":[{"text":"Note that it is the "},{"code":true,"text":"kth"},{"text":" largest element in the sorted order, not the "},{"code":true,"text":"kth"},{"text":" distinct element."}]},{"type":"paragraph","children":[{"text":" "}]},{"type":"paragraph","children":[{"bold":true,"text":"Example 1:"}]},{"type":"code-block","children":[{"bold":true,"text":"Input:"},{"text":" nums = [3,2,1,5,6,4], k = 2\n"},{"bold":true,"text":"Output:"},{"text":" 5\n"}]},{"type":"paragraph","children":[{"bold":true,"text":"Example 2:"}]},{"type":"code-block","children":[{"bold":true,"text":"Input:"},{"text":" nums = [3,2,3,1,2,4,5,5,6], k = 4\n"},{"bold":true,"text":"Output:"},{"text":" 4\n"}]},{"type":"paragraph","children":[{"text":" "}]},{"type":"paragraph","children":[{"bold":true,"text":"Constraints:"}]},{"type":"bulleted-list","children":[{"type":"list-item","children":[{"type":"list-item-child","children":[{"code":true,"text":"1 <= k <= nums.length <= 104"}]}]},{"type":"list-item","children":[{"type":"list-item-child","children":[{"code":true,"text":"-104 <= nums[i] <= 104"}]}]}]},{"type":"paragraph","children":[{"text":""}]},{"type":"heading-one","children":[{"text":"Solution:"}]},{"type":"paragraph","children":[{"text":"For solution, special thanks to "},{"href":"https://leetcode.com/constantine786","type":"link","children":[{"text":"constantine786"}],"className":"link__Lpjq","openInNewTab":true},{"text":""}]},{"type":"class","children":[{"type":"code-block","children":[{"text":"class Solution:\n def findKthLargest(self, nums: List[int], k: int) -> int: \n return sorted(nums)[-k]"}]}],"className":"python"},{"type":"paragraph","children":[{"text":""}]}]}},"categories":[{"name":"LeetCode","slug":"leetcode"},{"name":"Python","slug":"python"}]}},"__N_SSG":true}