FastPrepStreaming Top-K Frequent Elements
Problems/Streaming Top-K Frequent Elements

Streaming Top-K Frequent Elements

NVIDIA logoNVIDIA● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA phone screen for a full-time role. The report asks for streaming top-K frequent elements and points toward frequency buckets instead of a heap. It leaves out how queries are written and the tie order. Here we use a finite set of updates and queries.

Our version is about 93% the same as the reported question.

Process a finite sequence of streaming operations. Each operation is one of:

  • [0, value]: add one occurrence of value to the stream.
  • [1, k]: return the k distinct values with the highest frequencies among all values added so far.

For every query, order values by decreasing frequency. When frequencies tie, order the smaller value first. Return one row per query, in query order.

Design the update path around frequency buckets rather than maintaining a size-k heap for every query.

Function

streamTopK(operations: int[][]) → int[][]

Examples

Example 1

operations = [[0,4],[0,2],[0,4],[1,2],[0,2],[0,3],[1,3]]return = [[4,2],[2,4,3]]

The first query sees frequencies 4:2 and 2:1. At the second query, 2 and 4 tie at two occurrences, so 2 comes first.

Example 2

operations = [[0,5],[0,3],[0,5],[0,3],[1,1],[0,3],[1,2]]return = [[3],[3,5]]

The first query breaks a frequency tie by value. The later update makes 3 strictly more frequent than 5.

Example 3

operations = [[0,-1],[0,7],[0,-1],[0,7],[0,5],[1,3]]return = [[-1,7,5]]

Values -1 and 7 tie at frequency two and appear in ascending numeric order before 5.

Constraints

  • 1 <= operations.length <= 5000.
  • Every operation contains exactly two integers.
  • Add values satisfy -10^9 <= value <= 10^9.
  • Each query satisfies 1 <= k <= the number of distinct values added before that query.
  • At least one operation is a query.

More NVIDIA Phone Screen questions

  • Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
  • Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Merge Multiple Sorted StreamsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
  • Versioned Snapshot SetOpenAI · PHONE SCREENOpenAI interview questions
  • Interview Slot BookingTrueFoundry · PHONE SCREEN
  • Config Store with Priority OverridesMicrosoft · PHONE SCREENMicrosoft interview questions
  • Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • In-Memory Database with TTL and Historical QueriesZip · PHONE SCREENZip interview questions
  • Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
  • Temporal Key-Field Database with Prefix ScansThe Trade Desk · OA

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int[][] streamTopK(int[][] operations) {
        // Write your code here.
    }
}
Checking account…