Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given an unsorted array containing â€˜Nâ€™ integers. You need to find â€˜Kâ€™ largest elements from the given array. Also, you need to return the elements in non-decreasing order.

Detailed explanation

```
1 <= T <= 100
1 <= N <= 10^4
1<= K <= N
-10^9 <= ARR[i] <= 10^9
Where â€˜Tâ€™ is the number of test cases, â€˜Nâ€™ is the size of the array, â€˜Kâ€™ is the number of elements you need to return as an answer and ARR[i] is the size of the array of elements.
Time Limit: 1 sec
```

```
2
4 2
3 4 2 1
5 1
2 2 3 3 1
```

```
3 4
3
```

```
Test case 1:
If we sort the array then it will look like: [1, 2, 3, 4]. The 2 largest elements will be [3, 4].
Test case 2:
If we sort the array then it will look like: [1, 2, 2, 3, 3]. Then the largest element will be [3].
```

```
2
5 5
0 10 1 2 2
6 2
-2 12 -1 1 20 1
```

```
0 1 2 2 10
12 20
```