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 continuous stream of numbers
Implement add(DATA) function to add ...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at JPMorgan Chase & Co.
Q. Count Subarrays with Given XOR Problem Statement You are given an array of integ...read more
Q. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
Q. Merge Two Sorted Linked Lists Problem Statement You are provided with two sorted...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for JPMorgan Chase & Co. Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 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

