Smallest K Numbers

Practice Smallest K Numbers for free on NudgeCode: Easy, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Given an integer array nums and k (0 <= k <= nums.length), return the k smallest numbers in increasing order. Equal values count separately.

Example

nums = [3,4,1,2,5], k = 3  ->  [1,2,3]
nums = [5,5,1], k = 2      ->  [1,5]

The two 5s count as two numbers, so the second smallest is 5.

Constraints