Harpreet's Newsletter

Harpreet's Newsletter

Kth Largest Element in a Stream

Google Interview Question

Harpreet Singh's avatar
Harpreet Singh
Sep 05, 2025
∙ Paid

Problem Overview

Difficulty: Easy

Implement a class named KthLargest that keeps track of test scores and always tells us the kth highest score after each new submission.

Original Input: 
· k = 2
· nums = [2, 4, 5, 8]

add(1)
· Output = 5
· Reason: 2nd highest score is 5

add(9)
· Output = 8
· Reason: 2nd highest score is 8
User's avatar

Continue reading this post for free, courtesy of Harpreet Singh.

Or purchase a paid subscription.
© 2026 Harpreet Singh · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture