Otter.ai may need to identify the highest-scoring transcript segments, speakers, or search results for a ranking feature. Given a list of integers, return the k largest elements while preserving duplicate values. The result must be sorted in descending order.
Use an algorithm that avoids fully sorting the input when k is much smaller than n.
Implement k_largest(nums, k).
nums, a list of integers, and k, an integer.k largest values from nums, sorted from largest to smallest.nums.def k_largest(nums, k):