Select a Kth-Largest Occurrence without Full Sorting

Quick Overview

Select a kth-largest occurrence without full sorting by retaining a bounded min-heap with duplicates.

Select a Kth-Largest Occurrence without Full Sorting

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return the kth largest value in an integer array, counting repeated values separately. This means position k in descending sorted order, not the kth distinct value. Seek a solution that does not sort the entire input. ```cpp int findKthLargest(vector<int>& nums, int k); ``` ### Examples ```text Input: nums = [7,2,7,4,9], k = 3 Output: 7 ``` ```text Input: nums = [-5,-2,-8], k = 2 Output: -5 ``` ### Constraints - `1 <= k <= nums.length <= 100000`. - Values lie between -10000 and 10000.

Overview: Select a kth-largest occurrence without full sorting by retaining a bounded min-heap with duplicates.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the kth largest value in an integer array, counting repeated values separately. This means position k in descending sorted order, not the kth distinct value. Seek a solution that does not sort the entire input.

int findKthLargest(vector<int>& nums, int k);

Examples

Input: nums = [7,2,7,4,9], k = 3
Output: 7
Input: nums = [-5,-2,-8], k = 2
Output: -5

Constraints

  • 1 <= k <= nums.length <= 100000 .
  • Values lie between -10000 and 10000.