Member-only story

Kth Largest Element 👐🏼 in a Stream 🌊 | Daily LeetCode Challenge | Day 8 | Coding Interview

Ganesh Prasad
4 min readApr 8, 2022

--

Leetcode 703, Kth largest element
LeetCode Challenge Day 8: Kth Largest Element (703)

Let’s see along with passing this challenge how should we handle problems with streaming data. We will discuss the no-brainer brute force version as well as the efficient one.

If you are preparing for an upcoming coding interview, check out my list of problems for 30 Days.

Description

We are given a stream of integers nums and an integer k, we have to find the kth largest element of the stream from the sorted version of the nums.

There is a function add() that accepts a number to add to the stream nums and returns the kth largest element.

Leetcode 703, Kth largest element
The 3rd largest element
Example 1:
Input: nums = [4, 3, 9, 6], k = 4
add(7) = 4
add(8) = 6
add(1) = 3
Explanation: The sorted version of nums becomes [9, 6, 4, 3].
- adding 7 to the stream we get, [9, 7, 6, 4, 3]…

--

--

Ganesh Prasad
Ganesh Prasad

Written by Ganesh Prasad

Backend Developer at Appscrip | C++ veteran, 💜 Dart

No responses yet