SchoolabeSchoolabe
CoursesProgramsCompaniesQuizPrepAbout
Schoolabe

Learn, Practice, Ace Coding

ProgramsCompaniesTutorialsPracticeQuizInterview PrepAssessmentGATE 2026Job Ready
AboutContactCareersBlog
DocumentationAPI ReferenceCommunitySupport
Privacy PolicyTermsRefund PolicyCookie Policy

© 2026 Schoolabe

amazon · software-engineer · data-structures

Given a stream of integers, design a data structure that can return the top-K elements at any time. Explain the time and space trade-offs.

Difficulty: Medium

Overview

Assesses heap usage, streaming constraints, and complexity reasoning.

Example Answer

  • Use a min-heap of size K; push each element and pop when size exceeds K.
  • Time O(n log K), space O(K). For frequent queries, keep heap updated incrementally.

Tips

  • Clarify constraints: K, total elements, memory limits.
  • Compare min-heap vs. order statistics tree.
  • Explain update and query complexity.

Your Actions

Bookmarks show up in Profile → Career Prep → Saved Questions and on the company page under Saved Questions.

AI Assistant

No previous questionNext: How would you design a rate limiter that supports burst traffic and quick lookups?