Solution to K Least Numbers from Jobdu

27 Aug

Question (in Chinese): http://ac.jobdu.com/problem.php?pid=1371

Question Name: K Least Numbers

Question Description: Given an integer array and an integer K, find the sorted K least numbers in the original array.

Input: the input might contain multiple test cases. Each test case contains two lines. The first line includes two integers N and K (1 <= K <= N <= 200000). The second line includes N integers as the input array.

Output: For each test case, print the K least numbers in increasing order.

The solution with Java’s built-in priority queue is:

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!