Back to problems

Top-K Using a Priority Queue

Algorithm · Uber · Easy

Prompt: Top-K (Priority Queue) You are given an integer array nums and an integer k. Return the largest k values contained in the array, in any order. Parameters nums: List[int] - the array of n integers nums[i]. k: int - the integer k representing the number of largest elements to return. Return Value Returns the largest k elements of nums as a List[int], in any order. Constraints 1 [5, 6] The output contains the two greatest values in the array; their order is unrestricted.

Checking your access…