Your question is Finding the M Largest Elements. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
PingOne monitoring may need to identify the largest event-volume measurements from a batch of observations. Given an integer array and an integer m, return the m largest values in descending order.
Duplicate values count separately. For example, if the largest values include two occurrences of 9, both must appear in the result. You may assume the input is valid and contains at least m values.
Implement top_m_largest(nums, m):
nums, a non-empty list of integers, and m, an integer between 1 and len(nums).m largest values from nums, sorted in descending order.Your solution should avoid sorting the entire array when m is much smaller than len(nums). Explain the data structure you choose and its time and space complexity.
def top_m_largest(nums, m):