Given an array, the task is to print K smallest elements from the array but they must be in the same order as they are in given array.
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains two Integers N and K and the second line contains N space separated elements.
For each test case, print the K smallest elements in new line.
5 4 2 1 2
1 2 3 4 5 6 7
1 2 3 4 5
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.