Katkat

Maintain k-th largest in a stream

GoogleSoftware Engineer · Onsite

Last updated

This question evaluates understanding of data structures and streaming algorithms for maintaining k-th order statistics under dynamic inserts, emphasizing time-space trade-offs and correct handling of duplicates.

Design and implement a class KthLargest that, given an integer k and an initial list of integers, supports: (

  1. KthLargest(k, nums): constructor; (
  2. add(val): adds val to the data structure and returns the current k-th largest element. Achieve O(log k) time per insertion and O(k) space. Describe your data structures, handle duplicates, and analyze complexity.