Login

All Problems

Problem title

Difficulty

Avg time to solve

N-th Fibonacci Number

Moderate

40 mins

Product Of Array Except Self

Easy

26 mins

K Largest Element

Moderate

10 mins

Search In Rotated Sorted Array

Moderate

30 mins

Two Sum

Easy

10 mins

Subset OR

Moderate

20 mins

Find Unique

Easy

--

Count all sub-arrays having sum divisible by k

Moderate

15 mins

Average Marks

Easy

5 mins

Sum Of Max And Min

Easy

10 mins

Problem

Submissions

79

Avg. time to solve

10 min

Success Rate

90%

Problem Statement

```
The first line of the input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains two space-separated positive integers ‘N’ and ‘K’ denoting the number of the elements present in the array and count of the largest elements you need to return as the answer respectively.
The second line of each test case contains ‘N’ space-separated integers denoting the elements of the array.
```

```
The only line of output of each test case should contain ‘K’ largest elements in the array in non-decreasing order.
Print the output of each test case in a separate line.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
Can you solve this in less than O(N*log(N)) time complexity?
```

```
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
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code