Question bank › Heap
Dsa Heap Easy

Kth Largest Element in Stream

You are tasked with finding the Kth largest element in a stream of integers. Each time a new integer is received, you need to print the current Kth largest element. If the stream has fewer than K elements, return None. Input format: The first line contains two integers K (1 <= K <= 1000) and N (0 <= N <= 10000), the size of the kth largest to find and the number of new elements in the stream. The next N lines contain one integer each, representing the stream elements. Each integer can be negative or positive. Output format: For each new integer in the stream, print the current Kth largest element or 'None' if there are fewer than K elements. Example: Input: 3 5 3 1 5 10 2 Output: None 1 3 3 3

Key concepts

heapstreamdynamic

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.