{"id":22513732,"url":"https://github.com/emahtab/kth-largest-element-in-an-array","last_synced_at":"2026-02-25T13:38:46.175Z","repository":{"id":79525598,"uuid":"242293626","full_name":"eMahtab/kth-largest-element-in-an-array","owner":"eMahtab","description":"kth largest element in an array","archived":false,"fork":false,"pushed_at":"2020-02-22T08:20:43.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-17T16:56:48.992Z","etag":null,"topics":["heap","leetcode","problem-solving"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-02-22T06:43:13.000Z","updated_at":"2020-02-22T08:20:45.000Z","dependencies_parsed_at":"2023-05-10T17:16:00.351Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/kth-largest-element-in-an-array","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/kth-largest-element-in-an-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fkth-largest-element-in-an-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fkth-largest-element-in-an-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fkth-largest-element-in-an-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fkth-largest-element-in-an-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/kth-largest-element-in-an-array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fkth-largest-element-in-an-array/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281802034,"owners_count":26564007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heap","leetcode","problem-solving"],"created_at":"2024-12-07T03:14:13.344Z","updated_at":"2025-10-30T11:53:03.800Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# kth-largest-element-in-an-array\n## https://leetcode.com/problems/kth-largest-element-in-an-array\n\nFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.\n```\nExample 1:\n\nInput: [3,2,1,5,6,4] and k = 2\nOutput: 5\n\nExample 2:\n\nInput: [3,2,3,1,2,4,5,5,6] and k = 4\nOutput: 4\n```\n**Note: You may assume k is always valid, 1 ≤ k ≤ array's length.**\n\n## Implementation 1 : Sorting\n\n```java\nclass Solution {\n    public int findKthLargest(int[] nums, int k) {\n        Arrays.sort(nums);\n        return nums[nums.length - k];\n    }\n}\n```\n## Implementation 2 : Heap\n\n```java\nclass Solution {\n    \n    public int findKthLargest(int[] nums, int k) {\n       PriorityQueue\u003cInteger\u003e minHeap = new PriorityQueue\u003c\u003e(); \n       // just keep k largest elements in the min heap\n       for (int num: nums) {\n            if(minHeap.size() \u003c k){\n                     minHeap.add(num);\n            } else {\n                if(num \u003e minHeap.peek()) {\n                     minHeap.poll();\n                     minHeap.add(num);\n                  }\n            }\n        }\n       return minHeap.peek();    \n    }\n}\n```\n\n# References :\nhttps://www.youtube.com/watch?v=3d0ORD8Qnk8\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fkth-largest-element-in-an-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fkth-largest-element-in-an-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fkth-largest-element-in-an-array/lists"}