Reported July 2026
Googleheap priority queue

Fixed-K Kth Largest Stream

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

The whole problem rests on one data structure: a min-heap capped at size k. If you've got the Google OA invite from July 2026 sitting in your inbox, this is the one to recognize in the first thirty seconds. It's a streaming kth-largest problem with a fixed rank, duplicates counted separately, and up to 200000 total values. The hinted pattern says binary search, but the heap is the cleaner route. Know the heap, write it cold, and you're done early. StealthCoder runs invisibly on your screen as a safety net if you blank mid-assessment, but this one is learnable tonight.

The problem

You are given a fixed rank k, an initial array of integers initialValues, and an array additions whose values arrive in order.
After each value in additions is inserted, report the k-th largest value among every value seen so far. Duplicate occurrences occupy separate positions in the ranking.
Return one result for each arriving value, in the same order as additions.
Implement kthLargestAfterEachAdd(k, initialValues, additions).

Function
kthLargestAfterEachAdd(k: int, initialValues: int[], additions: int[]) → int[]

Examples
Example 1
k = 3
initialValues = [4,5,8,2]
additions = [3,5,10,9,4]
return = [4,5,5,8,8]
After adding 3, the three largest values are 8, 5, 4. Later additions raise the third-largest value first to 5 and then to 8.
Example 2
k = 2
initialValues = [5,5]
additions = [5,4,6]
return = [5,5,5]
Repeated values occupy separate ranks. Even after 6 arrives, the second-largest value remains 5.
Example 3
k = 1
initialValues = []
additions = [-10,-5,-7]
return = [-10,-5,-5]
With k = 1, each result is the maximum value seen so far.

Constraints
0 <= initialValues.length <= 200000.
1 <= additions.length <= 200000.
initialValues.length + additions.length <= 200000.
1 <= k <= initialValues.length + 1.
Every value fits in a signed 32-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Keep a min-heap holding only the k largest values seen so far. The root is always the k-th largest. Seed it by pushing every value from initialValues, popping whenever size exceeds k. Then for each addition, push it, pop if size exceeds k, and record the root. Each step is O(log k), so the total is O((n + m) log k), well inside 200000 values. The constraint k <= initialValues.length + 1 guarantees the heap has k items after the first addition, so the root is always valid. The common pitfall is deduping values. Don't. Example 2 shows duplicates hold separate ranks. Another trap is sorting after every insert, which goes quadratic. A binary-search insert into a sorted list works, but array shifting hurts at this size. If you freeze on the live OA, StealthCoder is the hedge that reads the problem and hands you the heap solution.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Fixed-K Kth Largest Stream cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as kth largest element in a stream. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Fixed-K Kth Largest Stream FAQ

What's the trick to this Google kth largest stream problem?+

Use a min-heap that never grows past size k. The smallest item in it is the k-th largest overall. Push each new value, pop if the size exceeds k, then read the root. That's the entire solution.

How hard is this one really?+

Easy to medium. If you've seen the classic kth largest in a stream problem, it's nearly identical. The only twist is returning a result after every addition, and seeding the heap from the initial array first.

Do duplicates need special handling?+

No. Duplicates take separate ranks, as Example 2 shows with k = 2 and values 5, 5, 5. Push them like any other number. Deduping with a set would give wrong answers, so avoid it.

Is binary search the right approach here?+

You can binary-search an insertion point in a sorted list, but shifting elements makes it slow at 200000 values. The heap gives O(log k) per step with no shifting. Use the heap unless your language lacks a priority queue.

How do I prepare in 48 hours?+

Write the heap solution from scratch twice, in your OA language. Test the three examples, plus an empty initialValues case with k = 1. Know your language's heap API cold, especially whether it's min or max by default.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it