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!
Select
Add answer anonymously...

Capgemini Senior Software Engineer interview questions & answers

A Senior Software Engineer was asked 1w agoQ. What coding languages are you well-versed in?
A Senior Software Engineer was asked 1mo agoQ. Write SQL queries demonstrating the use of GROUP BY and HAVING clauses.
A Senior Software Engineer was asked 1mo agoQ. Implement the Factory Design Pattern.

Popular interview questions of Senior Software Engineer

A Senior Software Engineer was asked 3d agoQ1. What coding languages are you well-versed in?
A Senior Software Engineer was asked 4w agoQ2. Write SQL queries demonstrating the use of GROUP BY and HAVING clauses.
A Senior Software Engineer was asked 1mo agoQ3. Implement the Factory Design Pattern.

Top HR questions asked in Capgemini Senior Software Engineer

A Senior Software Engineer was asked 8mo agoQ1. Why do you want to join Capgemini?
A Senior Software Engineer was asked 8mo agoQ2. Tell me about yourself.
A Senior Software Engineer was asked 10mo agoQ3. What are the metrics used in your project?
Capgemini Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits