Kth Largest Number Problem Statement
You are given a continuous stream of numbers, and the task is to determine the kth largest number at any moment during the stream.
Explanation:
A specialized data structure must be designed, capable of handling an indefinite number of integers from this stream. This data structure should allow for two main operations:
1. add(DATA): Incorporates an integer into the stream's current pool of numbers. 2. int getKthLargest(): Retrieves the kth largest number from the pool.
You will receive q queries, categorized into two types:
1. Type '1 val': Add an integer 'val' to the stream's pool. 2. Type '2': Retrieve and return the kth largest number from the existing pool.
Input:
The first line contains two space-separated integers 'Q' and 'K', indicating the total number of queries and the required position of the largest number, respectively. The second line contains 'K' space-separated integers as the initial pool. The next 'Q' lines specify queries of the given types. For type 1, the input line includes 'QUERYTYPE' and 'DATA'. For type 2, the input line only has the query type number.
Output:
For each Type 2 query, output the kth largest integer from the pool. Each result should be in a new line.
Example:
Input: 5 3
4 5 8
1 3
2
1 10
2
1 9
Output:
5
8
Constraints:
- 1 <= Q <= 10^4
- 1 <= K <= 10^5
- 1 <= QUERYTYPE <= 2
- 1 <= DATA <= 10^9
- Time Limit: 1 second
Note:
No need for explicit output; focus on function implementation as output processing is pre-handled.
Be the first one to answer
Add answer anonymously...
Top Capgemini Senior Software Engineer interview questions & answers
Popular interview questions of Senior Software Engineer
Top HR questions asked in Capgemini Senior Software Engineer
>
Capgemini Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app