Error
|
|
---|---|
@Ibrahim Nash | 6420 |
@blackshadows | 6376 |
@mb1973 | 5594 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@kirtidee18 | 3673 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3412 |
Complete Leaderboard | |
|
|
@codersgroup18 | 783 |
@Manikanta punnam | 605 |
@sriramgoparaju99 | 566 |
@praveenbgp6 | 529 |
@rdakka | 526 |
@prankursharma31 | 518 |
@yashkaril4 | 517 |
@purohitmn02 | 467 |
@sonamnigam1999 | 443 |
@sonamkumari63928 | 441 |
@shubhamstudent5 | 433 |
Complete Leaderboard |
Given an input stream arr[] of n integers, find the kth largest element for each element in the stream.
Example 1:
Input: k = 4, n = 6 arr[] = {1, 2, 3, 4, 5, 6} Output: -1 -1 -1 1 2 3 Explanation: k = 4 For 1, the 4th largest element doesn't exist so we print -1. For 2, the 4th largest element doesn't exist so we print -1. For 3, the 4th largest element doesn't exist so we print -1. For 4, the 4th largest element is 1. For 5, the 4th largest element is 2. for 6, the 4th largest element is 3.
Example 2:
Input: k = 1, n = 2 arr[] = {3, 4} Output: 3 4 Explanation: For the 1st and 2nd element the 1st largest element is itself.
Your Task:
You don't need to read input or print anything. Your task is to complete the function kthLargest() which takes 2 Integers k, and n and also an array arr[] of size n as input and returns the kth largest element in the stream.
Expected Time Complexity: O(nlogk)
Expected Auxiliary Space: O(n)
Constraints:
1 ≤ k ≤ n ≤ 105
1 ≤ arr[i] ≤ 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes