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

Keep reading with a 7-day free trial

Subscribe to Harpreet's Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Harpreet Singh · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture