
Asked in Capgemini
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.

AnswerBot
4mo
Design a data structure to find the kth largest number in a continuous stream of integers.
Design a specialized data structure to handle an indefinite number of integers from the stream.
Implement 'add(...read more
Help your peers!
Add answer anonymously...
Top Senior Software Engineer Interview Questions Asked at Capgemini
Q. What coding languages are you well-versed in?
Q. Write SQL queries demonstrating the use of GROUP BY and HAVING clauses.
Q. What is the difference between a hash set and a tree set?
Interview Questions Asked to Senior Software Engineer at Other Companies
Top Skill-Based Questions for Capgemini Senior Software Engineer
Web Development Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

